Skip to content

Instantly share code, notes, and snippets.

@peyerluk
Last active January 2, 2016 15:39
Show Gist options
  • Save peyerluk/8324555 to your computer and use it in GitHub Desktop.
Save peyerluk/8324555 to your computer and use it in GitHub Desktop.
dropAndRecreateTable = (name, setupMethod) ->
knex.schema.dropTableIfExists(name).then ->
knex.schema.createTable(name, setupMethod)
createDocumentPublicationsTable = (done) ->
command = dropAndRecreateTable 'document_publications', (t) ->
t.increments('id').primary()
t.integer('document_id').notNullable()
t.integer('revision_id').notNullable()
t.integer('user_id')
t.text('html').notNullable()
t.string('slug').notNullable()
t.integer('publication_number').notNullable()
t.dateTime('created_at').notNullable()
t.dateTime('updated_at').notNullable()
t.unique ['document_id', 'publication_number'],
'index_document_publications_on_document_id_and_publication_nr'
t.unique ['revision_id', 'document_id'],
'index_document_publications_on_revision_id_and_document_id'
command.exec(done)
@matteoagosti
Copy link

Thanks, even refactoring the drop and create :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment