Last active
March 7, 2016 18:13
-
-
Save wlaurance/10758516 to your computer and use it in GitHub Desktop.
time_entries table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dbm = require("db-migrate") | |
async = require 'async' | |
_ = require 'underscore' | |
type = dbm.dataType | |
table = "time_entries" | |
exports.up = (db, callback) -> | |
t = """ | |
create table #{table}( | |
"id" uuid PRIMARY KEY | |
DEFAULT uuid_generate_v4(), | |
"userId" uuid NOT NULL, | |
"projectId" uuid NOT NULL, | |
"message" character varying, | |
"start" timestamptz, | |
"end" timestamptz, | |
"duration" real | |
) | |
""" | |
r = [ | |
""" | |
add constraint "user_id_f_key" FOREIGN KEY ("userId") REFERENCES users("id") | |
""", | |
""" | |
add constraint "project_id_f_key" FOREIGN KEY ("projectId") REFERENCES projects("id") | |
""" | |
] | |
r = _.map r, (s) -> "alter table #{table} #{s}" | |
async.eachSeries _.flatten([t, r]), | |
(q, c) -> db.runSql(q, c) | |
, callback | |
exports.down = (db, callback) -> | |
if process.env.DROP_TABLES | |
db.dropTable table, callback | |
else | |
callback() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment