-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.go
More file actions
266 lines (249 loc) · 5.26 KB
/
Copy pathtemplates.go
File metadata and controls
266 lines (249 loc) · 5.26 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package main
import (
"fmt"
"os"
"strings"
)
var builtInTemplates = map[string]string{
"e-commerce": templateECommerce,
"saas": templateSaaS,
"social": templateSocial,
}
func listTemplates() []string {
names := make([]string, 0, len(builtInTemplates))
for name := range builtInTemplates {
names = append(names, name)
}
return names
}
func getTemplate(name string) (string, error) {
tmpl, ok := builtInTemplates[strings.ToLower(name)]
if !ok {
return "", fmt.Errorf("unknown template %q (available: %s)", name, strings.Join(listTemplates(), ", "))
}
return tmpl, nil
}
func RunTemplate(name, dbType string, preview int) error {
tmpl, err := getTemplate(name)
if err != nil {
return err
}
return runSchemaBytes([]byte(tmpl), dbType, preview, fmt.Sprintf("template:%s", name))
}
func SaveTemplate(name, outputPath string) error {
tmpl, err := getTemplate(name)
if err != nil {
return err
}
return os.WriteFile(outputPath, []byte(tmpl), 0644)
}
const templateECommerce = `version: "1.0"
tables:
- name: customers
count: 1000
columns:
- name: id
type: int
primary: true
- name: first_name
type: first_name
- name: last_name
type: last_name
- name: email
type: email
- name: phone
type: phone
- name: city
type: city
- name: country
type: country
- name: created_at
type: timestamp
- name: products
count: 500
columns:
- name: id
type: int
primary: true
- name: name
type: sentence
- name: description
type: paragraph
- name: category
type: enum
values: [Electronics, Clothing, Home, Sports, Books, Food]
- name: price
type: float
min: 9.99
max: 999.99
- name: stock
type: int
min: 0
max: 1000
- name: created_at
type: timestamp
- name: orders
count: 5000
columns:
- name: id
type: int
primary: true
- name: customer_id
type: fk
ref: customers.id
- name: total
type: float
min: 10.0
max: 2000.0
- name: status
type: enum
values: [pending, paid, shipped, delivered, cancelled]
- name: created_at
type: timestamp
- name: order_items
count: 10000
columns:
- name: id
type: int
primary: true
- name: order_id
type: fk
ref: orders.id
- name: product_id
type: fk
ref: products.id
- name: quantity
type: int
min: 1
max: 10
- name: unit_price
type: float
min: 9.99
max: 999.99
- name: created_at
type: timestamp
`
const templateSaaS = `version: "1.0"
tables:
- name: tenants
count: 50
columns:
- name: id
type: int
primary: true
- name: name
type: company
- name: domain
type: email
- name: plan
type: enum
values: [free, starter, pro, enterprise]
- name: created_at
type: timestamp
- name: users
count: 500
columns:
- name: id
type: int
primary: true
- name: tenant_id
type: fk
ref: tenants.id
- name: first_name
type: first_name
- name: last_name
type: last_name
- name: email
type: email
- name: role
type: enum
values: [admin, editor, viewer]
- name: created_at
type: timestamp
- name: subscriptions
count: 400
columns:
- name: id
type: int
primary: true
- name: user_id
type: fk
ref: users.id
- name: status
type: enum
values: [active, paused, cancelled, expired]
- name: price
type: float
min: 9.99
max: 299.99
- name: created_at
type: timestamp
- name: invoices
count: 1000
columns:
- name: id
type: int
primary: true
- name: subscription_id
type: fk
ref: subscriptions.id
- name: amount
type: float
min: 9.99
max: 299.99
- name: status
type: enum
values: [draft, sent, paid, overdue]
- name: created_at
type: timestamp
`
const templateSocial = `version: "1.0"
tables:
- name: users
count: 1000
columns:
- name: id
type: int
primary: true
- name: username
type: email
- name: full_name
type: full_name
- name: bio
type: sentence
- name: created_at
type: timestamp
- name: posts
count: 5000
columns:
- name: id
type: int
primary: true
- name: user_id
type: fk
ref: users.id
- name: content
type: paragraph
- name: likes_count
type: int
min: 0
max: 10000
- name: created_at
type: timestamp
- name: comments
count: 10000
columns:
- name: id
type: int
primary: true
- name: post_id
type: fk
ref: posts.id
- name: user_id
type: fk
ref: users.id
- name: content
type: sentence
- name: created_at
type: timestamp
`