-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmigrations.moon
121 lines (87 loc) · 2.94 KB
/
migrations.moon
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
db = require "lapis.db.postgres"
schema = require "lapis.db.schema"
import create_table, create_index, drop_table, add_column from schema
{
:boolean, :varchar, :integer, :text, :foreign_key, :double, :time, :numeric, :serial, :enum
} = schema.types
{
[1]: =>
create_table "games", {
{"id", serial}
{"comp", varchar}
{"uid", varchar}
{"user", varchar}
{"url", varchar}
{"title", varchar}
{"downloads", text}
{"num_downloads", integer}
{"screenshots", text null: true}
{"num_screenshots", integer}
{"votes_received", integer}
{"votes_given", integer}
{"is_jam", boolean default: db.NULL, null: true}
{"have_details", boolean default: false}
{"created_at", time}
{"updated_at", time}
"PRIMARY KEY(id)"
}
create_index "games", "comp", "uid", unique: true
create_index "games", "comp", "title"
create_index "games", "votes_received"
create_index "games", "votes_given"
create_table "collections", {
{"name", varchar}
{"comp", varchar}
{"uid", varchar}
"PRIMARY KEY(name, comp, uid)"
}
[2]: =>
db.query "alter table games alter column title type text"
db.query 'alter table games alter column "user" type text'
[3]: =>
create_table "events", {
{"id", serial}
{"slug", varchar null: true}
{"type", enum}
{"key", varchar null: true}
{"name", text}
{"start_date", time null: true}
{"end_date", time null: true}
{"created_at", time}
{"updated_at", time}
"PRIMARY KEY(id)"
}
create_index "events", "slug", unique: true
add_column "games", "event_id", foreign_key null: true
create_table "game_data", {
{"game_id", serial}
{"data", "json"}
"PRIMARY KEY (game_id)"
}
[4]: =>
db.query "alter table games alter column downloads drop not null"
db.query "alter table games alter column downloads type json using downloads::json"
db.query "alter table games alter column screenshots type json using screenshots::json"
[5]: =>
create_index "games", "event_id", "uid", unique: true
db.query "alter table games alter column comp drop not null"
[6]: =>
add_column "events", "games_count", integer null: true, default: db.NULL
add_column "events", "last_refreshed_at", time null: true
[7]: =>
drop_table "collections"
create_table "collection_games", {
{"name", varchar}
{"event_id", foreign_key}
{"game_id", foreign_key}
"PRIMARY KEY(name, game_id)"
}
create_index "collection_games", "event_id", "name"
create_index "collection_games", "game_id"
[8]: =>
add_column "games", "user_url", varchar null: true
[9]: =>
db.query [[create extension if not exists pg_trgm]]
db.query [[create index games_user on games using gin("user" gin_trgm_ops)]]
db.query [[create index games_title on games using gin(title gin_trgm_ops)]]
}