ru.Bee 2.5.4 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/db/structure.rb +433 -114
- data/lib/rubee/cli/db.rb +67 -16
- data/lib/rubee.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df9da4aa005f2ec38a95abf69fcbfae1136b7bca3090cfee309c3cc4fb37c32d
|
|
4
|
+
data.tar.gz: b8a5a2e187cb44e32a3cdff131cc29046d2a2fb44a876b4d76f8899188365752
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ceb90376fbdd108a4948762554a266957e59b99f19a9bd2a1949ef44829f9562072335c6727a8f0d6afcca988182d42f4dfe72522fc1629c1af6622ef6cf09ab
|
|
7
|
+
data.tar.gz: 98e3407e1113417ecf1f6d9c4db0d63f9768c79d79431c49d6eb78bb586d2411dbc59c9c72b1ddfd2c62403915d9fa546b1a2341142fd39aaa92570199d230c4
|
data/lib/db/structure.rb
CHANGED
|
@@ -1,126 +1,445 @@
|
|
|
1
1
|
STRUCTURE = {
|
|
2
|
-
users: {
|
|
3
|
-
id: {
|
|
4
|
-
generated: false,
|
|
5
|
-
allow_null: false,
|
|
6
|
-
default: nil,
|
|
7
|
-
db_type: 'INTEGER',
|
|
8
|
-
primary_key: true,
|
|
9
|
-
auto_increment: true,
|
|
10
|
-
type: 'integer',
|
|
11
|
-
ruby_default: nil,
|
|
12
|
-
},
|
|
13
|
-
email: {
|
|
14
|
-
generated: false,
|
|
15
|
-
allow_null: true,
|
|
16
|
-
default: nil,
|
|
17
|
-
db_type: 'varchar(255)',
|
|
18
|
-
primary_key: false,
|
|
19
|
-
type: 'string',
|
|
20
|
-
ruby_default: nil,
|
|
21
|
-
max_length: 255,
|
|
22
|
-
},
|
|
23
|
-
password: {
|
|
24
|
-
generated: false,
|
|
25
|
-
allow_null: true,
|
|
26
|
-
default: nil,
|
|
27
|
-
db_type: 'varchar(255)',
|
|
28
|
-
primary_key: false,
|
|
29
|
-
type: 'string',
|
|
30
|
-
ruby_default: nil,
|
|
31
|
-
max_length: 255,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
2
|
accounts: {
|
|
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
|
-
|
|
3
|
+
columns: {
|
|
4
|
+
id: {
|
|
5
|
+
generated: false,
|
|
6
|
+
allow_null: false,
|
|
7
|
+
default: nil,
|
|
8
|
+
db_type: "INTEGER",
|
|
9
|
+
primary_key: true,
|
|
10
|
+
auto_increment: true,
|
|
11
|
+
type: "integer",
|
|
12
|
+
ruby_default: nil
|
|
13
|
+
},
|
|
14
|
+
addres: {
|
|
15
|
+
generated: false,
|
|
16
|
+
allow_null: true,
|
|
17
|
+
default: nil,
|
|
18
|
+
db_type: "varchar(255)",
|
|
19
|
+
primary_key: false,
|
|
20
|
+
type: "string",
|
|
21
|
+
ruby_default: nil,
|
|
22
|
+
max_length: 255
|
|
23
|
+
},
|
|
24
|
+
user_id: {
|
|
25
|
+
generated: false,
|
|
26
|
+
allow_null: true,
|
|
27
|
+
default: nil,
|
|
28
|
+
db_type: "INTEGER",
|
|
29
|
+
primary_key: false,
|
|
30
|
+
type: "integer",
|
|
31
|
+
ruby_default: nil
|
|
32
|
+
},
|
|
33
|
+
created: {
|
|
34
|
+
generated: false,
|
|
35
|
+
allow_null: true,
|
|
36
|
+
default: nil,
|
|
37
|
+
db_type: "datetime",
|
|
38
|
+
primary_key: false,
|
|
39
|
+
type: "datetime",
|
|
40
|
+
ruby_default: nil
|
|
41
|
+
},
|
|
42
|
+
updated: {
|
|
43
|
+
generated: false,
|
|
44
|
+
allow_null: true,
|
|
45
|
+
default: nil,
|
|
46
|
+
db_type: "datetime",
|
|
47
|
+
primary_key: false,
|
|
48
|
+
type: "datetime",
|
|
49
|
+
ruby_default: nil
|
|
50
|
+
}
|
|
63
51
|
},
|
|
52
|
+
foreign_keys: [
|
|
53
|
+
{
|
|
54
|
+
columns: [
|
|
55
|
+
"user_id"
|
|
56
|
+
],
|
|
57
|
+
references: {
|
|
58
|
+
table: "users",
|
|
59
|
+
columns: nil
|
|
60
|
+
},
|
|
61
|
+
on_delete: "no_action",
|
|
62
|
+
on_update: "no_action"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
64
65
|
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
addresses: {
|
|
67
|
+
columns: {
|
|
68
|
+
id: {
|
|
69
|
+
generated: false,
|
|
70
|
+
allow_null: false,
|
|
71
|
+
default: nil,
|
|
72
|
+
db_type: "INTEGER",
|
|
73
|
+
primary_key: true,
|
|
74
|
+
auto_increment: true,
|
|
75
|
+
type: "integer",
|
|
76
|
+
ruby_default: nil
|
|
77
|
+
},
|
|
78
|
+
city: {
|
|
79
|
+
generated: false,
|
|
80
|
+
allow_null: true,
|
|
81
|
+
default: nil,
|
|
82
|
+
db_type: "varchar(255)",
|
|
83
|
+
primary_key: false,
|
|
84
|
+
type: "string",
|
|
85
|
+
ruby_default: nil,
|
|
86
|
+
max_length: 255
|
|
87
|
+
},
|
|
88
|
+
state: {
|
|
89
|
+
generated: false,
|
|
90
|
+
allow_null: true,
|
|
91
|
+
default: nil,
|
|
92
|
+
db_type: "varchar(255)",
|
|
93
|
+
primary_key: false,
|
|
94
|
+
type: "string",
|
|
95
|
+
ruby_default: nil,
|
|
96
|
+
max_length: 255
|
|
97
|
+
},
|
|
98
|
+
zip: {
|
|
99
|
+
generated: false,
|
|
100
|
+
allow_null: true,
|
|
101
|
+
default: nil,
|
|
102
|
+
db_type: "varchar(255)",
|
|
103
|
+
primary_key: false,
|
|
104
|
+
type: "string",
|
|
105
|
+
ruby_default: nil,
|
|
106
|
+
max_length: 255
|
|
107
|
+
},
|
|
108
|
+
street: {
|
|
109
|
+
generated: false,
|
|
110
|
+
allow_null: true,
|
|
111
|
+
default: nil,
|
|
112
|
+
db_type: "varchar(255)",
|
|
113
|
+
primary_key: false,
|
|
114
|
+
type: "string",
|
|
115
|
+
ruby_default: nil,
|
|
116
|
+
max_length: 255
|
|
117
|
+
},
|
|
118
|
+
apt: {
|
|
119
|
+
generated: false,
|
|
120
|
+
allow_null: true,
|
|
121
|
+
default: nil,
|
|
122
|
+
db_type: "varchar(255)",
|
|
123
|
+
primary_key: false,
|
|
124
|
+
type: "string",
|
|
125
|
+
ruby_default: nil,
|
|
126
|
+
max_length: 255
|
|
127
|
+
},
|
|
128
|
+
user_id: {
|
|
129
|
+
generated: false,
|
|
130
|
+
allow_null: true,
|
|
131
|
+
default: nil,
|
|
132
|
+
db_type: "INTEGER",
|
|
133
|
+
primary_key: false,
|
|
134
|
+
type: "integer",
|
|
135
|
+
ruby_default: nil
|
|
136
|
+
},
|
|
137
|
+
created: {
|
|
138
|
+
generated: false,
|
|
139
|
+
allow_null: true,
|
|
140
|
+
default: nil,
|
|
141
|
+
db_type: "datetime",
|
|
142
|
+
primary_key: false,
|
|
143
|
+
type: "datetime",
|
|
144
|
+
ruby_default: nil
|
|
145
|
+
},
|
|
146
|
+
updated: {
|
|
147
|
+
generated: false,
|
|
148
|
+
allow_null: true,
|
|
149
|
+
default: nil,
|
|
150
|
+
db_type: "datetime",
|
|
151
|
+
primary_key: false,
|
|
152
|
+
type: "datetime",
|
|
153
|
+
ruby_default: nil
|
|
154
|
+
}
|
|
75
155
|
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
156
|
+
foreign_keys: [
|
|
157
|
+
{
|
|
158
|
+
columns: [
|
|
159
|
+
"user_id"
|
|
160
|
+
],
|
|
161
|
+
references: {
|
|
162
|
+
table: "users",
|
|
163
|
+
columns: nil
|
|
164
|
+
},
|
|
165
|
+
on_delete: "no_action",
|
|
166
|
+
on_update: "no_action"
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
carrots: {
|
|
171
|
+
columns: {
|
|
172
|
+
id: {
|
|
173
|
+
generated: false,
|
|
174
|
+
allow_null: false,
|
|
175
|
+
default: nil,
|
|
176
|
+
db_type: "INTEGER",
|
|
177
|
+
primary_key: true,
|
|
178
|
+
auto_increment: true,
|
|
179
|
+
type: "integer",
|
|
180
|
+
ruby_default: nil
|
|
181
|
+
},
|
|
182
|
+
color: {
|
|
183
|
+
generated: false,
|
|
184
|
+
allow_null: false,
|
|
185
|
+
default: nil,
|
|
186
|
+
db_type: "varchar(255)",
|
|
187
|
+
primary_key: false,
|
|
188
|
+
type: "string",
|
|
189
|
+
ruby_default: nil,
|
|
190
|
+
max_length: 255
|
|
191
|
+
},
|
|
192
|
+
created: {
|
|
193
|
+
generated: false,
|
|
194
|
+
allow_null: true,
|
|
195
|
+
default: nil,
|
|
196
|
+
db_type: "datetime",
|
|
197
|
+
primary_key: false,
|
|
198
|
+
type: "datetime",
|
|
199
|
+
ruby_default: nil
|
|
200
|
+
},
|
|
201
|
+
updated: {
|
|
202
|
+
generated: false,
|
|
203
|
+
allow_null: true,
|
|
204
|
+
default: nil,
|
|
205
|
+
db_type: "datetime",
|
|
206
|
+
primary_key: false,
|
|
207
|
+
type: "datetime",
|
|
208
|
+
ruby_default: nil
|
|
209
|
+
}
|
|
84
210
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
211
|
+
foreign_keys: []
|
|
212
|
+
},
|
|
213
|
+
clients: {
|
|
214
|
+
columns: {
|
|
215
|
+
id: {
|
|
216
|
+
generated: false,
|
|
217
|
+
allow_null: false,
|
|
218
|
+
default: nil,
|
|
219
|
+
db_type: "INTEGER",
|
|
220
|
+
primary_key: true,
|
|
221
|
+
auto_increment: true,
|
|
222
|
+
type: "integer",
|
|
223
|
+
ruby_default: nil
|
|
224
|
+
},
|
|
225
|
+
name: {
|
|
226
|
+
generated: false,
|
|
227
|
+
allow_null: true,
|
|
228
|
+
default: nil,
|
|
229
|
+
db_type: "varchar(255)",
|
|
230
|
+
primary_key: false,
|
|
231
|
+
type: "string",
|
|
232
|
+
ruby_default: nil,
|
|
233
|
+
max_length: 255
|
|
234
|
+
},
|
|
235
|
+
digest_password: {
|
|
236
|
+
generated: false,
|
|
237
|
+
allow_null: true,
|
|
238
|
+
default: nil,
|
|
239
|
+
db_type: "varchar(255)",
|
|
240
|
+
primary_key: false,
|
|
241
|
+
type: "string",
|
|
242
|
+
ruby_default: nil,
|
|
243
|
+
max_length: 255
|
|
244
|
+
},
|
|
245
|
+
created: {
|
|
246
|
+
generated: false,
|
|
247
|
+
allow_null: true,
|
|
248
|
+
default: nil,
|
|
249
|
+
db_type: "datetime",
|
|
250
|
+
primary_key: false,
|
|
251
|
+
type: "datetime",
|
|
252
|
+
ruby_default: nil
|
|
253
|
+
},
|
|
254
|
+
updated: {
|
|
255
|
+
generated: false,
|
|
256
|
+
allow_null: true,
|
|
257
|
+
default: nil,
|
|
258
|
+
db_type: "datetime",
|
|
259
|
+
primary_key: false,
|
|
260
|
+
type: "datetime",
|
|
261
|
+
ruby_default: nil
|
|
262
|
+
}
|
|
93
263
|
},
|
|
264
|
+
foreign_keys: []
|
|
94
265
|
},
|
|
95
266
|
comments: {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
267
|
+
columns: {
|
|
268
|
+
id: {
|
|
269
|
+
generated: false,
|
|
270
|
+
allow_null: false,
|
|
271
|
+
default: nil,
|
|
272
|
+
db_type: "INTEGER",
|
|
273
|
+
primary_key: true,
|
|
274
|
+
auto_increment: true,
|
|
275
|
+
type: "integer",
|
|
276
|
+
ruby_default: nil
|
|
277
|
+
},
|
|
278
|
+
text: {
|
|
279
|
+
generated: false,
|
|
280
|
+
allow_null: true,
|
|
281
|
+
default: nil,
|
|
282
|
+
db_type: "varchar(255)",
|
|
283
|
+
primary_key: false,
|
|
284
|
+
type: "string",
|
|
285
|
+
ruby_default: nil,
|
|
286
|
+
max_length: 255
|
|
287
|
+
},
|
|
288
|
+
user_id: {
|
|
289
|
+
generated: false,
|
|
290
|
+
allow_null: true,
|
|
291
|
+
default: nil,
|
|
292
|
+
db_type: "INTEGER",
|
|
293
|
+
primary_key: false,
|
|
294
|
+
type: "integer",
|
|
295
|
+
ruby_default: nil
|
|
296
|
+
},
|
|
297
|
+
created: {
|
|
298
|
+
generated: false,
|
|
299
|
+
allow_null: true,
|
|
300
|
+
default: nil,
|
|
301
|
+
db_type: "datetime",
|
|
302
|
+
primary_key: false,
|
|
303
|
+
type: "datetime",
|
|
304
|
+
ruby_default: nil
|
|
305
|
+
},
|
|
306
|
+
updated: {
|
|
307
|
+
generated: false,
|
|
308
|
+
allow_null: true,
|
|
309
|
+
default: nil,
|
|
310
|
+
db_type: "datetime",
|
|
311
|
+
primary_key: false,
|
|
312
|
+
type: "datetime",
|
|
313
|
+
ruby_default: nil
|
|
314
|
+
}
|
|
105
315
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
316
|
+
foreign_keys: []
|
|
317
|
+
},
|
|
318
|
+
users: {
|
|
319
|
+
columns: {
|
|
320
|
+
id: {
|
|
321
|
+
generated: false,
|
|
322
|
+
allow_null: false,
|
|
323
|
+
default: nil,
|
|
324
|
+
db_type: "INTEGER",
|
|
325
|
+
primary_key: true,
|
|
326
|
+
auto_increment: true,
|
|
327
|
+
type: "integer",
|
|
328
|
+
ruby_default: nil
|
|
329
|
+
},
|
|
330
|
+
email: {
|
|
331
|
+
generated: false,
|
|
332
|
+
allow_null: true,
|
|
333
|
+
default: nil,
|
|
334
|
+
db_type: "varchar(255)",
|
|
335
|
+
primary_key: false,
|
|
336
|
+
type: "string",
|
|
337
|
+
ruby_default: nil,
|
|
338
|
+
max_length: 255
|
|
339
|
+
},
|
|
340
|
+
password: {
|
|
341
|
+
generated: false,
|
|
342
|
+
allow_null: true,
|
|
343
|
+
default: nil,
|
|
344
|
+
db_type: "varchar(255)",
|
|
345
|
+
primary_key: false,
|
|
346
|
+
type: "string",
|
|
347
|
+
ruby_default: nil,
|
|
348
|
+
max_length: 255
|
|
349
|
+
},
|
|
350
|
+
created: {
|
|
351
|
+
generated: false,
|
|
352
|
+
allow_null: true,
|
|
353
|
+
default: nil,
|
|
354
|
+
db_type: "datetime",
|
|
355
|
+
primary_key: false,
|
|
356
|
+
type: "datetime",
|
|
357
|
+
ruby_default: nil
|
|
358
|
+
},
|
|
359
|
+
updated: {
|
|
360
|
+
generated: false,
|
|
361
|
+
allow_null: true,
|
|
362
|
+
default: nil,
|
|
363
|
+
db_type: "datetime",
|
|
364
|
+
primary_key: false,
|
|
365
|
+
type: "datetime",
|
|
366
|
+
ruby_default: nil
|
|
367
|
+
}
|
|
124
368
|
},
|
|
369
|
+
foreign_keys: []
|
|
125
370
|
},
|
|
126
|
-
|
|
371
|
+
posts: {
|
|
372
|
+
columns: {
|
|
373
|
+
id: {
|
|
374
|
+
generated: false,
|
|
375
|
+
allow_null: false,
|
|
376
|
+
default: nil,
|
|
377
|
+
db_type: "INTEGER",
|
|
378
|
+
primary_key: true,
|
|
379
|
+
auto_increment: true,
|
|
380
|
+
type: "integer",
|
|
381
|
+
ruby_default: nil
|
|
382
|
+
},
|
|
383
|
+
user_id: {
|
|
384
|
+
generated: false,
|
|
385
|
+
allow_null: true,
|
|
386
|
+
default: nil,
|
|
387
|
+
db_type: "INTEGER",
|
|
388
|
+
primary_key: false,
|
|
389
|
+
type: "integer",
|
|
390
|
+
ruby_default: nil
|
|
391
|
+
},
|
|
392
|
+
comment_id: {
|
|
393
|
+
generated: false,
|
|
394
|
+
allow_null: true,
|
|
395
|
+
default: nil,
|
|
396
|
+
db_type: "INTEGER",
|
|
397
|
+
primary_key: false,
|
|
398
|
+
type: "integer",
|
|
399
|
+
ruby_default: nil
|
|
400
|
+
},
|
|
401
|
+
created: {
|
|
402
|
+
generated: false,
|
|
403
|
+
allow_null: true,
|
|
404
|
+
default: nil,
|
|
405
|
+
db_type: "datetime",
|
|
406
|
+
primary_key: false,
|
|
407
|
+
type: "datetime",
|
|
408
|
+
ruby_default: nil
|
|
409
|
+
},
|
|
410
|
+
updated: {
|
|
411
|
+
generated: false,
|
|
412
|
+
allow_null: true,
|
|
413
|
+
default: nil,
|
|
414
|
+
db_type: "datetime",
|
|
415
|
+
primary_key: false,
|
|
416
|
+
type: "datetime",
|
|
417
|
+
ruby_default: nil
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
foreign_keys: [
|
|
421
|
+
{
|
|
422
|
+
columns: [
|
|
423
|
+
"comment_id"
|
|
424
|
+
],
|
|
425
|
+
references: {
|
|
426
|
+
table: "comments",
|
|
427
|
+
columns: nil
|
|
428
|
+
},
|
|
429
|
+
on_delete: "no_action",
|
|
430
|
+
on_update: "no_action"
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
columns: [
|
|
434
|
+
"user_id"
|
|
435
|
+
],
|
|
436
|
+
references: {
|
|
437
|
+
table: "users",
|
|
438
|
+
columns: nil
|
|
439
|
+
},
|
|
440
|
+
on_delete: "no_action",
|
|
441
|
+
on_update: "no_action"
|
|
442
|
+
}
|
|
443
|
+
]
|
|
444
|
+
}
|
|
445
|
+
}
|
data/lib/rubee/cli/db.rb
CHANGED
|
@@ -37,8 +37,16 @@ module Rubee
|
|
|
37
37
|
generate_structure
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def schema(
|
|
41
|
-
STRUCTURE.
|
|
40
|
+
def schema(argv)
|
|
41
|
+
target_table_hash = argv[2] ? { argv[2].to_sym => STRUCTURE[argv[2].to_sym] } : nil
|
|
42
|
+
(target_table_hash || STRUCTURE).each do |table_name, table_def|
|
|
43
|
+
unless Rubee::SequelObject::DB.table_exists?(table_name.to_sym)
|
|
44
|
+
color_puts("Table #{table_name} not found", color: :red)
|
|
45
|
+
next
|
|
46
|
+
end
|
|
47
|
+
columns = table_def[:columns]
|
|
48
|
+
foreign_keys = table_def[:foreign_keys] || []
|
|
49
|
+
|
|
42
50
|
# Table header
|
|
43
51
|
color_puts(
|
|
44
52
|
"--- #{table_name}",
|
|
@@ -46,22 +54,21 @@ module Rubee
|
|
|
46
54
|
style: :bold
|
|
47
55
|
)
|
|
48
56
|
|
|
57
|
+
# Columns
|
|
49
58
|
columns.each do |column_name, meta|
|
|
50
59
|
parts = []
|
|
51
60
|
|
|
52
61
|
# column name
|
|
53
|
-
|
|
54
|
-
parts << col_text
|
|
62
|
+
parts << "- #{column_name}"
|
|
55
63
|
|
|
56
64
|
# PK
|
|
57
|
-
if meta[:primary_key]
|
|
58
|
-
parts << "(PK)"
|
|
59
|
-
end
|
|
65
|
+
parts << "(PK)" if meta[:primary_key]
|
|
60
66
|
|
|
61
67
|
# type
|
|
62
|
-
if meta[:db_type]
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
parts << "type (#{meta[:db_type]})" if meta[:db_type]
|
|
69
|
+
|
|
70
|
+
# nullable
|
|
71
|
+
parts << "nullable" if meta[:allow_null]
|
|
65
72
|
|
|
66
73
|
line = parts.join(", ")
|
|
67
74
|
|
|
@@ -71,6 +78,30 @@ module Rubee
|
|
|
71
78
|
)
|
|
72
79
|
end
|
|
73
80
|
|
|
81
|
+
# Foreign keys
|
|
82
|
+
if foreign_keys.any?
|
|
83
|
+
puts
|
|
84
|
+
color_puts(" Foreign keys:", color: :magenta, style: :bold)
|
|
85
|
+
|
|
86
|
+
foreign_keys.each do |fk|
|
|
87
|
+
cols = Array(fk[:columns]).join(", ")
|
|
88
|
+
|
|
89
|
+
ref_table =
|
|
90
|
+
fk.dig(:references, :table) ||
|
|
91
|
+
fk[:table]
|
|
92
|
+
|
|
93
|
+
ref_cols =
|
|
94
|
+
Array(fk.dig(:references, :columns)) || fk["id"]
|
|
95
|
+
|
|
96
|
+
fk_line = " - #{cols} → #{ref_table}(#{ref_cols.join(', ')})"
|
|
97
|
+
|
|
98
|
+
fk_line += " on delete #{fk[:on_delete]}" if fk[:on_delete]
|
|
99
|
+
fk_line += " on update #{fk[:on_update]}" if fk[:on_update]
|
|
100
|
+
|
|
101
|
+
color_puts(fk_line, color: :gray)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
74
105
|
puts
|
|
75
106
|
end
|
|
76
107
|
end
|
|
@@ -81,17 +112,37 @@ module Rubee
|
|
|
81
112
|
schema_hash = {}
|
|
82
113
|
|
|
83
114
|
Rubee::SequelObject::DB.tables.each do |table|
|
|
84
|
-
schema_hash[table] = {
|
|
115
|
+
schema_hash[table] = {
|
|
116
|
+
columns: {},
|
|
117
|
+
foreign_keys: [],
|
|
118
|
+
}
|
|
85
119
|
|
|
120
|
+
# Columns
|
|
86
121
|
Rubee::SequelObject::DB.schema(table).each do |column, details|
|
|
87
|
-
schema_hash[table][column] = details
|
|
122
|
+
schema_hash[table][:columns][column] = details
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Foreign keys
|
|
126
|
+
Rubee::SequelObject::DB.foreign_key_list(table).each do |fk|
|
|
127
|
+
schema_hash[table][:foreign_keys] << {
|
|
128
|
+
name: fk[:name],
|
|
129
|
+
columns: fk[:columns],
|
|
130
|
+
references: {
|
|
131
|
+
table: fk[:table],
|
|
132
|
+
columns: fk[:key],
|
|
133
|
+
},
|
|
134
|
+
on_delete: fk[:on_delete],
|
|
135
|
+
on_update: fk[:on_update],
|
|
136
|
+
}.compact
|
|
88
137
|
end
|
|
89
138
|
end
|
|
90
|
-
formatted_hash = JSON.pretty_generate(schema_hash)
|
|
91
|
-
.gsub(/"(\w+)":/, '\1:') # Convert keys to symbols
|
|
92
|
-
.gsub(': null', ': nil') # Convert `null` to `nil`
|
|
93
139
|
|
|
94
|
-
|
|
140
|
+
formatted_hash =
|
|
141
|
+
JSON.pretty_generate(schema_hash)
|
|
142
|
+
.gsub(/"(\w+)":/, '\1:')
|
|
143
|
+
.gsub(': null', ': nil')
|
|
144
|
+
file_path = File.join(Rubee::APP_ROOT, Rubee::LIB, "db/structure.rb")
|
|
145
|
+
File.open(file_path, 'w') do |file|
|
|
95
146
|
file.puts "STRUCTURE = #{formatted_hash}"
|
|
96
147
|
end
|
|
97
148
|
|
data/lib/rubee.rb
CHANGED