-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.js
96 lines (93 loc) · 2.28 KB
/
tables.js
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
const SQL_TYPES_TEXT = 'TEXT';
const SQL_TYPES_INTEGER = 'INTEGER';
const createSchema = (columns, uniqueConstraint = undefined) => {
const decoratedColumns = [
['id', `${SQL_TYPES_INTEGER} PRIMARY KEY`],
...columns,
['created_at', SQL_TYPES_INTEGER],
['updated_at', SQL_TYPES_INTEGER]
];
if (uniqueConstraint) {
const { indexName, columns } = uniqueConstraint;
return `${decoratedColumns.flatMap(([columnName, columnType]) => `${columnName} ${columnType}`).join(', ')}, CONSTRAINT ${indexName} UNIQUE (${columns.join(', ')})`
}
return `${decoratedColumns.flatMap(([columnName, columnType]) => `${columnName} ${columnType}`).join(', ')}`
}
export const tables = [
{
"prefix": "Generations",
"schema": createSchema([
['name', SQL_TYPES_TEXT],
])
},
{
"prefix": "Stages",
"schema": createSchema(
[
['generation_id', SQL_TYPES_INTEGER],
['parent_stage_id', SQL_TYPES_INTEGER]
]
)
},
{
"prefix": "StageSpirits",
"schema": createSchema(
[
['stage_id', SQL_TYPES_INTEGER],
['spirit_id', SQL_TYPES_INTEGER],
['parent_stage_spirit_id', SQL_TYPES_INTEGER],
],
{
indexName: 'unique_spirit_per_stage',
columns: [
'stage_id',
'spirit_id'
]
}
)
},
{
"prefix": "Spirits",
"schema": createSchema(
[
['sprite_sheet_uri', SQL_TYPES_TEXT],
['sprite_sheet_version_id', SQL_TYPES_INTEGER],
],
{
indexName: 'unique_sprite_sheet_uri_per_spirit',
columns: [
'sprite_sheet_uri'
]
}
)
},
{
"prefix": "SpriteSheetVersion",
"schema": createSchema(
[
['sprite_width_px', SQL_TYPES_INTEGER],
['sprite_height_px', SQL_TYPES_INTEGER],
['sprite_spacing_px', SQL_TYPES_INTEGER],
['sprite_scale', SQL_TYPES_INTEGER],
]
)
},
{
"prefix": "SpriteAttributes",
"schema": createSchema(
[
['spirit_id', SQL_TYPES_INTEGER],
['trait_name', SQL_TYPES_TEXT],
['variation_name', SQL_TYPES_TEXT],
],
{
indexName: 'unique_traits_per_spirit',
columns: [
'spirit_id',
'trait_name',
'variation_name',
]
}
)
},
]