通常mix.test清理测试数据库,但它不起作用.
这可能是因为我正在玩制作users架构,但不想使用我制作的东西,所以我摆脱了它.然后我重新开始为用户创建了一个与第一个不同的新模式.
当我再次尝试运行混合测试时,出现了一个错误,即某些字段不存在,应该存在新模式.
这里有人询问如何使用Ecto的时间戳为现有表添加时间戳?但是,接受的解决方案意味着每个新条目都具有相同的默认时间.我希望新条目具有正确的插入/更新时间.
例如.
# set default to given date to fill in all existing rows with timestamps
def change do
alter table(:my_table) do
timestamps(default: "2018-01-01 00:00:01")
end
end
Run Code Online (Sandbox Code Playgroud)
如果这是迁移中的所有内容,则无论插入/更新的日期如何,每个 inserted_at和updated_atfor :my_table将具有2018-01-01 00:00:01作为值.
我想做的是:
inserted_at并且updated_at应该null: false在将时间戳添加到新创建的表时使用它们.我有几个解决方案可以做到这一点,但它们看起来很混乱.我正在寻找是否有更清洁的方法来做到这一点,或者是否有选项来处理这个我错过的案例.
工作迁移1:
def up do
alter table(:my_table) do
timestamps(default: "now()")
end
execute("ALTER TABLE my_table ALTER COLUMN inserted_at SET DEFAULT now()")
execute("ALTER TABLE my_table ALTER COLUMN updated_at SET DEFAULT now()")
end
def down …Run Code Online (Sandbox Code Playgroud) 我有2个具有共享功能/路由的应用程序.例如,在两个应用程序中都有日记,目标跟踪,睡眠跟踪等,它们以相同的方式工作.还有特定于每个应用程序的路由.在AppA中,用户可以跟踪他们的心情,在AppB中,用户可以查看他们的医生的笔记.
有没有办法让一个伞形项目包含在/apps通用应用程序,AppA和AppB中?每个应用程序都有自己的路由器/控制器/模板等.AppA和AppB都需要GenericApp作为依赖项.到目前为止,我只看到了一个包含前端逻辑(web)的应用程序的伞状项目,其他应用程序是包含在其中的库.如何在多个应用程序之间进行路由?我可以采取另一种方法吗?
我在搜索中找到了这个问题和答案,但这并不是我想要的.它似乎遵循一个前端应用程序的模式,包括在其他库中.
尝试插入新房间时,我开始收到以下错误消息
** (Ecto.ConstraintError) constraint error when attempting to insert struct:
* unique: rooms_pkey
If you would like to convert this constraint into an error, please
call unique_constraint/3 in your changeset and define the proper
constraint name. The changeset defined the following constraints:
* unique: rooms_name_index
Run Code Online (Sandbox Code Playgroud)
主键不应该自动递增吗?什么会突然发生这个错误?插入是作为multi的一部分完成的,相关部分是:
|> Multi.insert(:room, Room.changeset(%Room{}, %{name: "service-user-care-team:" <> Integer.to_string(user.id)}))
Run Code Online (Sandbox Code Playgroud)
有关其他参考,请参阅我的架构,包括更改集
schema "rooms" do
field :name, :string
many_to_many :users, App.User, join_through: "user_rooms", on_delete: :delete_all
has_many :messages, App.Message
timestamps()
end
def changeset(struct, params \\ %{}) do
struct
|> …Run Code Online (Sandbox Code Playgroud) 我正在尝试对需要登录的路由进行负载测试.
我以前使用https://artillery.io/docs/index.html登出的路线工作正常.对于登录路由,我尝试beforeRequest使用函数调用来设置请求标头和正文.
config:
target: "https://www.mywebsite.com/"
phases:
- duration: 60
arrivalRate: 50
processor: "test.js"
scenarios:
- flow:
- post:
url: "/login"
beforeRequest: "setReqBody"
而我的beforeRequest看起来像这样:
function setReqBody(requestParams, context, ee, next) {
requestParams.body = {'email': 'user@mail.com', 'password': 'password', '_csrf_token': window.csrfToken}
return next();
}
我收到一个window未定义的错误.
我环顾四周,看看还有什么我可以用来负载测试凤凰,但没有太多运气.有没有其他方法可以登录并测试这些路线?或者我可以使用其他依赖项/库来执行此操作?