-
Notifications
You must be signed in to change notification settings - Fork 336
Expand file tree
/
Copy pathmigration.exs
More file actions
166 lines (136 loc) · 4.53 KB
/
migration.exs
File metadata and controls
166 lines (136 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
defmodule Ecto.Integration.Migration do
use Ecto.Migration
def change do
# IO.puts "TESTING MIGRATION LOCK"
# Process.sleep(10000)
create table(:users, comment: "users table") do
add :name, :string, comment: "name column"
add :custom_id, :uuid
timestamps()
end
create table(:posts) do
add :title, :string, size: 100
add :counter, :integer
add :blob, :binary
add :bid, :binary_id
add :uuid, :uuid
add :meta, :map
add :links, {:map, :string}
add :intensities, {:map, :float}
add :public, :boolean
add :cost, :decimal, precision: 2, scale: 1
add :visits, :integer
add :wrapped_visits, :integer
add :intensity, :float
add :author_id, :integer
add :posted, :date
add :composite_a, :integer
add :composite_b, :integer
timestamps(null: true)
end
create table(:posts_users, primary_key: false) do
add :post_id, references(:posts)
add :user_id, references(:users)
end
create table(:posts_users_pk) do
add :post_id, references(:posts)
add :user_id, references(:users)
timestamps()
end
# Add a unique index on uuid. We use this
# to verify the behaviour that the index
# only matters if the UUID column is not NULL.
create unique_index(:posts, [:uuid], comment: "posts index")
create table(:permalinks) do
add :uniform_resource_locator, :string
add :title, :string
add :post_id, references(:posts)
add :user_id, references(:users)
end
create unique_index(:permalinks, [:post_id])
create unique_index(:permalinks, [:uniform_resource_locator])
create table(:comments) do
add :text, :string, size: 100
add :lock_version, :integer, default: 1
add :post_id, references(:posts)
add :author_id, references(:users)
end
create table(:customs, primary_key: false) do
add :bid, :binary_id, primary_key: true
add :uuid, :uuid
end
create unique_index(:customs, [:uuid])
create table(:customs_customs, primary_key: false) do
add :custom_id1, references(:customs, column: :bid, type: :binary_id)
add :custom_id2, references(:customs, column: :bid, type: :binary_id)
end
create table(:barebones) do
add :num, :integer
end
create table(:transactions) do
add :num, :integer
end
create table(:lock_counters) do
add :count, :integer
end
create table(:orders) do
add :item, :map
add :items, :map
add :meta, :map
add :permalink_id, references(:permalinks)
end
unless :array_type in ExUnit.configuration()[:exclude] do
create table(:tags) do
add :ints, {:array, :integer}
add :uuids, {:array, :uuid}, default: []
add :items, {:array, :map}
end
create table(:array_loggings) do
add :uuids, {:array, :uuid}, default: []
timestamps()
end
end
create table(:composite_pk, primary_key: false) do
add :a, :integer, primary_key: true
add :b, :integer, primary_key: true
add :name, :string
end
create table(:composite_pk_composite_pk, primary_key: false) do
add :a_1, references(:composite_pk, column: :a, with: [b_1: :b], type: :integer)
add :b_1, :integer
add :a_2, references(:composite_pk, column: :a, with: [b_2: :b], type: :integer)
add :b_2, :integer
end
alter table(:posts) do
modify :composite_a, references(:composite_pk, column: :a, with: [composite_b: :b], type: :integer)
end
create table(:one_to_one_composite_pk) do
add :composite_a, references(:composite_pk, column: :a, with: [composite_b: :b], type: :integer)
add :composite_b, :integer
timestamps()
end
create unique_index(:one_to_one_composite_pk, [:composite_a, :composite_b])
create table(:corrupted_pk, primary_key: false) do
add :a, :string
end
create table(:posts_users_composite_pk) do
add :post_id, references(:posts), primary_key: true
add :user_id, references(:users), primary_key: true
timestamps()
end
create unique_index(:posts_users_composite_pk, [:post_id, :user_id])
create table(:usecs) do
add :naive_datetime_usec, :naive_datetime_usec
add :utc_datetime_usec, :utc_datetime_usec
end
create table(:bits) do
add :bit, :bit
end
create table(:loggings, primary_key: false) do
add :bid, :binary_id, primary_key: true
add :int, :integer
add :uuid, :uuid
timestamps()
end
end
end