1
1
exports . up = knex => {
2
2
return knex . schema
3
- // -------------------------------------
4
- // GROUPS
5
- // -------------------------------------
3
+ // =====================================
4
+ // MODEL TABLES
5
+ // =====================================
6
+ // ASSETS ------------------------------
7
+ . createTable ( 'assets' , table => {
8
+ table . increments ( 'id' ) . primary ( )
9
+ table . string ( 'filename' ) . notNullable ( )
10
+ table . string ( 'basename' ) . notNullable ( )
11
+ table . string ( 'ext' ) . notNullable ( )
12
+ table . enum ( 'kind' , [ 'binary' , 'image' ] ) . notNullable ( ) . defaultTo ( 'binary' )
13
+ table . string ( 'mime' ) . notNullable ( ) . defaultTo ( 'application/octet-stream' )
14
+ table . integer ( 'fileSize' ) . unsigned ( ) . comment ( 'In kilobytes' )
15
+ table . jsonb ( 'metadata' )
16
+ table . string ( 'createdAt' ) . notNullable ( )
17
+ table . string ( 'updatedAt' ) . notNullable ( )
18
+ } )
19
+ // ASSET FOLDERS -----------------------
20
+ . createTable ( 'assetFolders' , table => {
21
+ table . increments ( 'id' ) . primary ( )
22
+ table . string ( 'name' ) . notNullable ( )
23
+ table . string ( 'slug' ) . notNullable ( )
24
+ table . integer ( 'parentId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'assetFolders' )
25
+ } )
26
+ // COMMENTS ----------------------------
27
+ . createTable ( 'comments' , table => {
28
+ table . increments ( 'id' ) . primary ( )
29
+ table . text ( 'content' ) . notNullable ( )
30
+ table . string ( 'createdAt' ) . notNullable ( )
31
+ table . string ( 'updatedAt' ) . notNullable ( )
32
+ } )
33
+ // GROUPS ------------------------------
6
34
. createTable ( 'groups' , table => {
7
35
table . increments ( 'id' ) . primary ( )
8
-
9
36
table . string ( 'name' ) . notNullable ( )
10
37
table . string ( 'createdAt' ) . notNullable ( )
11
38
table . string ( 'updatedAt' ) . notNullable ( )
12
39
} )
13
- // -------------------------------------
14
- // LOCALES
15
- // -------------------------------------
40
+ // LOCALES -----------------------------
16
41
. createTable ( 'locales' , table => {
17
42
table . increments ( 'id' ) . primary ( )
18
-
19
43
table . string ( 'code' , 2 ) . notNullable ( ) . unique ( )
20
- table . json ( 'strings' )
44
+ table . jsonb ( 'strings' )
21
45
table . boolean ( 'isRTL' ) . notNullable ( ) . defaultTo ( false )
22
46
table . string ( 'name' ) . notNullable ( )
23
47
table . string ( 'nativeName' ) . notNullable ( )
24
48
table . string ( 'createdAt' ) . notNullable ( )
25
49
table . string ( 'updatedAt' ) . notNullable ( )
26
50
} )
27
- // -------------------------------------
28
- // SETTINGS
29
- // -------------------------------------
51
+ // PAGES -------------------------------
52
+ . createTable ( 'pages' , table => {
53
+ table . increments ( 'id' ) . primary ( )
54
+ table . string ( 'path' ) . notNullable ( )
55
+ table . string ( 'title' ) . notNullable ( )
56
+ table . string ( 'description' )
57
+ table . boolean ( 'isPublished' ) . notNullable ( ) . defaultTo ( false )
58
+ table . string ( 'publishStartDate' )
59
+ table . string ( 'publishEndDate' )
60
+ table . text ( 'content' )
61
+ table . string ( 'createdAt' ) . notNullable ( )
62
+ table . string ( 'updatedAt' ) . notNullable ( )
63
+ } )
64
+ // SETTINGS ----------------------------
30
65
. createTable ( 'settings' , table => {
31
66
table . increments ( 'id' ) . primary ( )
32
-
33
67
table . string ( 'key' ) . notNullable ( ) . unique ( )
34
- table . json ( 'value' )
68
+ table . jsonb ( 'value' )
69
+ table . string ( 'createdAt' ) . notNullable ( )
70
+ table . string ( 'updatedAt' ) . notNullable ( )
71
+ } )
72
+ // TAGS --------------------------------
73
+ . createTable ( 'tags' , table => {
74
+ table . increments ( 'id' ) . primary ( )
75
+ table . string ( 'tag' ) . notNullable ( ) . unique ( )
76
+ table . string ( 'title' )
35
77
table . string ( 'createdAt' ) . notNullable ( )
36
78
table . string ( 'updatedAt' ) . notNullable ( )
37
79
} )
38
- // -------------------------------------
39
- // USERS
40
- // -------------------------------------
80
+ // USERS -------------------------------
41
81
. createTable ( 'users' , table => {
42
82
table . increments ( 'id' ) . primary ( )
43
-
44
83
table . string ( 'email' ) . notNullable ( )
45
84
table . string ( 'name' ) . notNullable ( )
46
85
table . string ( 'provider' ) . notNullable ( ) . defaultTo ( 'local' )
@@ -54,22 +93,52 @@ exports.up = knex => {
54
93
55
94
table . unique ( [ 'provider' , 'email' ] )
56
95
} )
57
- // -------------------------------------
58
- // USER GROUPS
59
- // -------------------------------------
96
+ // =====================================
97
+ // RELATION TABLES
98
+ // =====================================
99
+ // PAGE TAGS ---------------------------
100
+ . createTable ( 'pageTags' , table => {
101
+ table . increments ( 'id' ) . primary ( )
102
+ table . integer ( 'pageId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'pages' )
103
+ table . integer ( 'tagId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'tags' )
104
+ } )
105
+ // USER GROUPS -------------------------
60
106
. createTable ( 'userGroups' , table => {
61
107
table . increments ( 'id' ) . primary ( )
62
-
63
108
table . integer ( 'userId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'users' )
64
109
table . integer ( 'groupId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'groups' )
65
110
} )
111
+ // =====================================
112
+ // REFERENCES
113
+ // =====================================
114
+ . table ( 'assets' , table => {
115
+ table . integer ( 'folderId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'assetFolders' )
116
+ table . integer ( 'authorId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'users' )
117
+ } )
118
+ . table ( 'comments' , table => {
119
+ table . integer ( 'pageId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'pages' )
120
+ table . integer ( 'authorId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'users' )
121
+ } )
122
+ . table ( 'pages' , table => {
123
+ table . string ( 'locale' , 2 ) . references ( 'code' ) . inTable ( 'locales' )
124
+ table . integer ( 'authorId' ) . unsigned ( ) . references ( 'id' ) . inTable ( 'users' )
125
+ } )
126
+ . table ( 'users' , table => {
127
+ table . string ( 'locale' , 2 ) . references ( 'code' ) . inTable ( 'locales' )
128
+ } )
66
129
}
67
130
68
131
exports . down = knex => {
69
132
return knex . schema
70
133
. dropTableIfExists ( 'userGroups' )
134
+ . dropTableIfExists ( 'pageTags' )
135
+ . dropTableIfExists ( 'assets' )
136
+ . dropTableIfExists ( 'assetFolders' )
137
+ . dropTableIfExists ( 'comments' )
71
138
. dropTableIfExists ( 'groups' )
72
139
. dropTableIfExists ( 'locales' )
140
+ . dropTableIfExists ( 'pages' )
73
141
. dropTableIfExists ( 'settings' )
142
+ . dropTableIfExists ( 'tags' )
74
143
. dropTableIfExists ( 'users' )
75
144
}
0 commit comments