Skip to content

Commit c719d93

Browse files
Yuriy BodarevYuriy Bodarev
Yuriy Bodarev
authored and
Yuriy Bodarev
committed
Operations seeds
1 parent 48b2291 commit c719d93

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/transactions_api/operations/operation.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Transactions.Operations.Operation do
1111
field :description, :string
1212

1313
belongs_to :type, Type
14-
belongs_to :user, User
14+
belongs_to :user, User, foreign_key: :user_id, type: :binary_id
1515
timestamps()
1616
end
1717

priv/repo/seeds.exs

+21-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,27 @@
1212

1313
alias Transactions.Repo;
1414
alias Transactions.Accounts.User;
15+
alias Transactions.Operations.Type;
16+
alias Transactions.Operations.Operation;
1517

18+
Repo.delete_all Operation
1619
Repo.delete_all User
20+
Repo.delete_all Type
1721

18-
Repo.insert!(%User{age: 25, email: "[email protected]", first_name: "James", last_name: "Bond"});
19-
Repo.insert!(%User{age: 36, email: "[email protected]", first_name: "Yurii", last_name: "Bodarev"});
20-
Repo.insert!(%User{age: 30, email: "[email protected]", first_name: "Ivan", last_name: "Zushko"});
21-
Repo.insert!(%User{age: 66, email: "[email protected]", first_name: "Deleted", last_name: "User", is_deleted: true});
22+
# Users
23+
user_james = Repo.insert!(%User{age: 25, email: "[email protected]", first_name: "James", last_name: "Bond"})
24+
user_yurii = Repo.insert!(%User{age: 36, email: "[email protected]", first_name: "Yurii", last_name: "Bodarev"})
25+
user_ivan = Repo.insert!(%User{age: 30, email: "[email protected]", first_name: "Ivan", last_name: "Zushko"})
26+
Repo.insert!(%User{age: 66, email: "[email protected]", first_name: "Deleted", last_name: "User", is_deleted: true})
27+
28+
# Operation types
29+
debit_operation_type = Repo.insert!(%Type{type: "debit", description: "remove an amount of money from a users's account"})
30+
credit_operation_type = Repo.insert!(%Type{type: "credit", description: "add an amount of money to a users's account"})
31+
32+
33+
# Operations
34+
%Operation{amount: 10.0, description: "Enumeration", user: user_james, type: credit_operation_type }
35+
|> Repo.insert!
36+
37+
%Operation{amount: -5.0, description: "Amazon sale", user: user_james, type: debit_operation_type }
38+
|> Repo.insert!

0 commit comments

Comments
 (0)