Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knex-ify MySQL Migrations #139

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
410 changes: 0 additions & 410 deletions dev-tools/mysql-migrations/001-create_mysql.sql

This file was deleted.

178 changes: 0 additions & 178 deletions dev-tools/mysql-migrations/002-mysql-utf8mb4.sql

This file was deleted.

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions dev-tools/mysql-migrations/005-deliverability-table.sql

This file was deleted.

1 change: 0 additions & 1 deletion dev-tools/mysql-migrations/006-make-org-features-text.sql

This file was deleted.

20 changes: 20 additions & 0 deletions migrations/20190224000000_add_campaign_creator_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Add creator_id column to campaign
exports.up = function(knex, Promise) {
return knex.schema.alterTable('campaign', (table) => {
table.integer('creator_id')
.unsigned()
.nullable()
.default(null)
.index()
.references('id')
.inTable('user')
})
}

// Drop creator_id column from campaign
exports.down = function(knex, Promise) {
return knex.schema.alterTable('campaign', (table) => {
table.dropForeign('creator_id')
table.dropColumn('creator_id')
})
}
15 changes: 15 additions & 0 deletions migrations/20190225000000_add_message_campaign_contact_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Add campaign_contact_id column to message
exports.up = function(knex, Promise) {
return knex.schema.alterTable('message', table => {
table.integer('campaign_contact_id').unsigned()
table.foreign('campaign_contact_id').references('campaign_contact.id')
})
}

// Drop campaign_contact_id column from message
exports.down = function(knex, Promise) {
return knex.schema.alterTable('message', table => {
table.dropForeign('campaign_contact_id')
table.dropColumn('campaign_contact_id')
})
}
13 changes: 13 additions & 0 deletions migrations/20190408000000_add_index_message_created_at.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Add index on message.created_at
exports.up = function(knex, Promise) {
return knex.schema.alterTable('message', table => {
table.index('created_at')
})
}

// Drop index on message.created_at
exports.down = function(knex, Promise) {
return knex.schema.alterTable('message', table => {
table.dropIndex('created_at')
})
}
17 changes: 17 additions & 0 deletions migrations/20190408010000_cascade_interaction_step_fkeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Cascade deletes from parent interaction steps down to children
exports.up = function(knex, Promise) {
return knex.schema.alterTable('interaction_step', table => {
table.dropForeign('parent_interaction_id')
table.foreign('parent_interaction_id')
.references('interaction_step.id')
.onDelete('CASCADE')
})
}

// Remove cascading deletes from interaction steps
exports.down = function(knex, Promise) {
return knex.schema.alterTable('interaction_step', table => {
table.dropForeign('parent_interaction_id')
table.foreign('parent_interaction_id').references('interaction_step.id')
})
}
30 changes: 30 additions & 0 deletions migrations/20190408020000_add_deliverability_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Create deliverability_report table
exports.up = function(knex, Promise) {
return knex.schema.createTable('deliverability_report', table => {
table.increments('id').primary()
table.timestamp('period_starts_at')
table.timestamp('period_ends_at')
table.timestamp('computed_at')
table.integer('count_total')
table.integer('count_delivered')
table.integer('count_sent')
table.integer('count_error')
table.string('domain', 191)
table.string('url_path', 191)

table.index('period_starts_at')
table.index('period_ends_at')
table.index('computed_at')
table.index('count_total')
table.index('count_delivered')
table.index('count_sent')
table.index('count_error')
table.index('domain')
table.index('url_path')
})
}

// Drop deliverability_report table
exports.down = function(knex, Promise) {
return knex.schema.dropTable('deliverability_report')
}