This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
104 lines (73 loc) · 2.42 KB
/
Cakefile
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
require "coffee-script"
require "coffee-script-mapped"
require "salad"
{spawn} = require "child_process"
Table = require "cli-table"
async = require "async"
initialized = false
init = (cb) =>
return cb() if initialized
initialized = true
env = process.env.NODE_ENV || "production"
Salad.Bootstrap.instance().init
env: env
App.sequelize.options.logging = false
cb()
# task 'db:clear', 'Clear the database', ->
# init =>
# sync = App.sequelize.sync(force: true)
# sync.on "success", =>
# console.log "Done synchronizing"
# # process.exit()
# sync.on "error", (err) =>
# App.Logger.error err if err
# App.Logger.error "Could not clear database. An error happened!"
# # process.exit()
option "-t", "--title [title]", "Migration title. Usage: cake -t foo db:migrations:create"
task 'db:migrations:create', 'Create a new migration', (options) ->
name = options.title or "unnamed"
migrate = spawn "./node_modules/salad/node_modules/.bin/sequelize", ["-c", name]
migrate.stdout.on "data", (data) =>
console.log data.toString().replace(/\n$/m, '')
migrate.stderr.on "data", (data) =>
console.log data.toString().replace(/\n$/m, '')
migrate.on "close", =>
console.log "Done"
task 'db:migrations:migrate', 'Migrate the database schema', ->
migrate = spawn "./node_modules/salad/node_modules/.bin/sequelize", ["-m"]
migrate.stdout.on "data", (data) =>
console.log data.toString().replace(/\n$/m, '')
migrate.stderr.on "data", (data) =>
console.log data.toString().replace(/\n$/m, '')
migrate.on "close", =>
console.log "Done"
task 'db:drop', 'Drop the database schema', ->
init =>
tables = [
"SequelizeMeta"
]
async.eachSeries tables,
(table, cb) =>
App.sequelize.query("DROP TABLE IF EXISTS \"#{table}\"").success =>
cb()
.error =>
console.error arguments
cb "fail"
(err) =>
console.log "done!"
task 'db:statistics', "Shows statistics for the database", ->
init =>
models = [
]
data = {}
async.eachSeries models,
iterator = (model, cb) =>
model.count (err, count) =>
data[model.name] = count
cb()
done = (err) =>
table = new Table
head: ["Object", "Amount"]
for key, val of data
table.push [key, val]
App.Logger.log "Object counts:\n" + table.toString()