This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
forked from erickzanardo/luna-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrations.lua
76 lines (69 loc) · 2.04 KB
/
migrations.lua
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
local schema = require("lapis.db.schema")
local db = require("lapis.db")
local types = schema.types
return {
[1] = function()
schema.create_table("articles", {
{ "id", types.serial },
{ "title", types.text },
{ "content", types.text },
{ "date", types.date },
"PRIMARY KEY (id)"
})
end;
[2] = function()
schema.create_table("authors", {
{ "id", types.serial },
{ "name", types.text },
{ "email", types.text },
{ "password", types.text },
"PRIMARY KEY (id)"
})
schema.add_column("articles", "author_id", types.foreign_key)
db.query("ALTER TABLE articles ADD CONSTRAINT author_fk FOREIGN KEY (author_id) REFERENCES authors (id)")
end;
[3] = function ()
db.insert("authors", {name = "luna_user", email = "luna_user@luna_blog", password = "luna"})
end;
[4] = function ()
schema.create_table("categories", {
{ "id", types.serial },
{ "name", types.text },
{ "slug", types.text },
"PRIMARY KEY (id)"
})
end;
[5] = function ()
schema.create_table("tags", {
{ "id", types.serial },
{ "name", types.text },
{ "slug", types.text },
"PRIMARY KEY (id)"
})
end;
[6] = function ()
schema.add_column("articles", "slug", types.text)
schema.add_column("articles", "published", types.boolean)
schema.add_column("articles", "category_id", types.foreign_key)
db.query("ALTER TABLE articles ADD CONSTRAINT category_fk FOREIGN KEY (category_id) REFERENCES categories (id)")
end;
[7] = function ()
schema.create_table("article_tags", {
{ "article_id", types.foreign_key },
{ "tag_id", types.foreign_key }
})
end;
[8] = function ()
db.insert("categories", {name = "Uncategorized", slug = "uncategorized"})
end;
[9] = function ()
schema.create_table("settings", {
{ "name", types.text },
{ "value", types.text },
"PRIMARY KEY (name)"
})
end;
[10] = function ()
db.query("ALTER TABLE Authors RENAME COLUMN name TO username;")
end
}