File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param { import("knex").Knex } knex
3+ * @returns { Promise<void> }
4+ */
5+ exports . up = async knex => {
6+ await knex . schema . hasTable ( "opt_in" ) . then ( async exists => {
7+ if ( exists ) return ;
8+ await knex . schema . createTable ( "opt_in" , table => {
9+ table . increments ( "id" )
10+ table . text ( "cell" ) . notNullable ( ) ;
11+ table . integer ( "assignment_id" ) . nullable ( ) ; ;
12+ table . integer ( "organization_id" ) . notNullable ( ) ;
13+ // Not in love with "reason_code", but doing so to match
14+ // opt_out table
15+ table . text ( "reason_code" ) . notNullable ( ) . defaultTo ( "" ) ;
16+ table . timestamp ( "created_at" ) . notNullable ( ) . defaultTo ( knex . fn . now ( ) ) ;
17+
18+ table . index ( "cell" ) ;
19+ table . index ( "assignment_id" ) ;
20+ table . foreign ( "assignment_id" ) . references ( "assignment.id" ) ;
21+ table . index ( "organization_id" ) ;
22+ table . foreign ( "organization_id" ) . references ( "organization.id" )
23+ } ) ;
24+ } ) ;
25+ } ;
26+
27+ /**
28+ * @param { import("knex").Knex } knex
29+ */
30+ exports . down = async function ( knex ) {
31+ return await knex . schema . dropTableIfExists ( "opt_in" ) ;
32+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param { import("knex").Knex } knex
3+ * @returns { Promise<void> }
4+ */
5+ exports . up = async knex => {
6+ await knex . schema . alterTable ( "campaign_contact" , table => {
7+ table
8+ . boolean ( "is_opted_in" )
9+ . defaultTo ( false ) ;
10+ } ) ;
11+ } ;
12+
13+ /**
14+ * @param { import("knex").Knex } knex
15+ * @returns { Promise<void> }
16+ */
17+ exports . down = async knex => {
18+ const isSqlite = / s q l i t e / . test ( knex . client . config . client ) ;
19+ if ( ! isSqlite ) {
20+ await knex . schema . alterTable ( "campaign_contact" , table => {
21+ table
22+ . boolean ( "is_opted_in" )
23+ . defaultTo ( false ) ;
24+ } ) ;
25+ }
26+ } ;
You can’t perform that action at this time.
0 commit comments