ru.Bee 2.5.4 → 2.5.6
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/db/test.db +0 -0
- data/lib/rubee/cli/db.rb +73 -16
- data/lib/rubee.rb +1 -1
- data/readme.md +14 -0
- 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: b3fd10a8289d2c40aa0f9709bdf87ad2d4ff6ad8238d76f321b7e534d365d84c
|
|
4
|
+
data.tar.gz: 05c6c2f8dd162d9952204ef603d65de7f03d4be83b857440e50a5c92556caa54
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75f0f5618b721651c6f2c3fdfe8cbd267b3b0a764b1bccbff39768b5f89903f16d8d435f5a3f4d4869635505afebf5870c2954448a780a0f3446767ffdcf2e35
|
|
7
|
+
data.tar.gz: ec7ce9f2c15cbc4eaf53118bb71f0d8a6559cbd57f82584718d9379c285eee366f33f8b66ded0363ce432f8eee55b5b15e84838bde3d65a46d5aa1b357613897
|
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/db/test.db
CHANGED
|
Binary file
|
data/lib/rubee/cli/db.rb
CHANGED
|
@@ -37,8 +37,22 @@ module Rubee
|
|
|
37
37
|
generate_structure
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def
|
|
41
|
-
|
|
40
|
+
def drop_tables(_argv)
|
|
41
|
+
out = Rubee::SequelObject::DB.tables.each { |table| Rubee::SequelObject::DB.drop_table(table, cascade: true) }
|
|
42
|
+
color_puts("These tables has been dropped for #{ENV['RACK_ENV']} env", color: :cyan)
|
|
43
|
+
color_puts(out, color: :gray)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def schema(argv)
|
|
47
|
+
target_table_hash = argv[2] ? { argv[2].to_sym => STRUCTURE[argv[2].to_sym] } : nil
|
|
48
|
+
(target_table_hash || STRUCTURE).each do |table_name, table_def|
|
|
49
|
+
unless Rubee::SequelObject::DB.table_exists?(table_name.to_sym)
|
|
50
|
+
color_puts("Table #{table_name} not found", color: :red)
|
|
51
|
+
next
|
|
52
|
+
end
|
|
53
|
+
columns = table_def[:columns]
|
|
54
|
+
foreign_keys = table_def[:foreign_keys] || []
|
|
55
|
+
|
|
42
56
|
# Table header
|
|
43
57
|
color_puts(
|
|
44
58
|
"--- #{table_name}",
|
|
@@ -46,22 +60,21 @@ module Rubee
|
|
|
46
60
|
style: :bold
|
|
47
61
|
)
|
|
48
62
|
|
|
63
|
+
# Columns
|
|
49
64
|
columns.each do |column_name, meta|
|
|
50
65
|
parts = []
|
|
51
66
|
|
|
52
67
|
# column name
|
|
53
|
-
|
|
54
|
-
parts << col_text
|
|
68
|
+
parts << "- #{column_name}"
|
|
55
69
|
|
|
56
70
|
# PK
|
|
57
|
-
if meta[:primary_key]
|
|
58
|
-
parts << "(PK)"
|
|
59
|
-
end
|
|
71
|
+
parts << "(PK)" if meta[:primary_key]
|
|
60
72
|
|
|
61
73
|
# type
|
|
62
|
-
if meta[:db_type]
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
parts << "type (#{meta[:db_type]})" if meta[:db_type]
|
|
75
|
+
|
|
76
|
+
# nullable
|
|
77
|
+
parts << "nullable" if meta[:allow_null]
|
|
65
78
|
|
|
66
79
|
line = parts.join(", ")
|
|
67
80
|
|
|
@@ -71,6 +84,30 @@ module Rubee
|
|
|
71
84
|
)
|
|
72
85
|
end
|
|
73
86
|
|
|
87
|
+
# Foreign keys
|
|
88
|
+
if foreign_keys.any?
|
|
89
|
+
puts
|
|
90
|
+
color_puts(" Foreign keys:", color: :magenta, style: :bold)
|
|
91
|
+
|
|
92
|
+
foreign_keys.each do |fk|
|
|
93
|
+
cols = Array(fk[:columns]).join(", ")
|
|
94
|
+
|
|
95
|
+
ref_table =
|
|
96
|
+
fk.dig(:references, :table) ||
|
|
97
|
+
fk[:table]
|
|
98
|
+
|
|
99
|
+
ref_cols =
|
|
100
|
+
Array(fk.dig(:references, :columns)) || fk["id"]
|
|
101
|
+
|
|
102
|
+
fk_line = " - #{cols} → #{ref_table}(#{ref_cols.join(', ')})"
|
|
103
|
+
|
|
104
|
+
fk_line += " on delete #{fk[:on_delete]}" if fk[:on_delete]
|
|
105
|
+
fk_line += " on update #{fk[:on_update]}" if fk[:on_update]
|
|
106
|
+
|
|
107
|
+
color_puts(fk_line, color: :gray)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
74
111
|
puts
|
|
75
112
|
end
|
|
76
113
|
end
|
|
@@ -81,17 +118,37 @@ module Rubee
|
|
|
81
118
|
schema_hash = {}
|
|
82
119
|
|
|
83
120
|
Rubee::SequelObject::DB.tables.each do |table|
|
|
84
|
-
schema_hash[table] = {
|
|
121
|
+
schema_hash[table] = {
|
|
122
|
+
columns: {},
|
|
123
|
+
foreign_keys: [],
|
|
124
|
+
}
|
|
85
125
|
|
|
126
|
+
# Columns
|
|
86
127
|
Rubee::SequelObject::DB.schema(table).each do |column, details|
|
|
87
|
-
schema_hash[table][column] = details
|
|
128
|
+
schema_hash[table][:columns][column] = details
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Foreign keys
|
|
132
|
+
Rubee::SequelObject::DB.foreign_key_list(table).each do |fk|
|
|
133
|
+
schema_hash[table][:foreign_keys] << {
|
|
134
|
+
name: fk[:name],
|
|
135
|
+
columns: fk[:columns],
|
|
136
|
+
references: {
|
|
137
|
+
table: fk[:table],
|
|
138
|
+
columns: fk[:key],
|
|
139
|
+
},
|
|
140
|
+
on_delete: fk[:on_delete],
|
|
141
|
+
on_update: fk[:on_update],
|
|
142
|
+
}.compact
|
|
88
143
|
end
|
|
89
144
|
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
145
|
|
|
94
|
-
|
|
146
|
+
formatted_hash =
|
|
147
|
+
JSON.pretty_generate(schema_hash)
|
|
148
|
+
.gsub(/"(\w+)":/, '\1:')
|
|
149
|
+
.gsub(': null', ': nil')
|
|
150
|
+
file_path = File.join(Rubee::APP_ROOT, Rubee::LIB, "db/structure.rb")
|
|
151
|
+
File.open(file_path, 'w') do |file|
|
|
95
152
|
file.puts "STRUCTURE = #{formatted_hash}"
|
|
96
153
|
end
|
|
97
154
|
|
data/lib/rubee.rb
CHANGED
data/readme.md
CHANGED
|
@@ -246,6 +246,20 @@ This will generate the following files
|
|
|
246
246
|
- text, type (varchar(255))
|
|
247
247
|
- user_id, type (INTEGER)
|
|
248
248
|
```
|
|
249
|
+
7. You can also rpint out the schema for the table you need
|
|
250
|
+
```bash
|
|
251
|
+
-> rubee db schema posts
|
|
252
|
+
--- posts
|
|
253
|
+
- id, (PK), type (INTEGER)
|
|
254
|
+
- user_id, type (INTEGER), nullable
|
|
255
|
+
- comment_id, type (INTEGER), nullable
|
|
256
|
+
- created, type (datetime), nullable
|
|
257
|
+
- updated, type (datetime), nullable
|
|
258
|
+
|
|
259
|
+
Foreign keys:
|
|
260
|
+
- comment_id → comments() on delete no_action on update no_action
|
|
261
|
+
- user_id → users() on delete no_action on update no_action
|
|
262
|
+
```
|
|
249
263
|
|
|
250
264
|
[Back to content](#content)
|
|
251
265
|
|