Skip to content

Commit 46ac8b6

Browse files
Introduce opt_in table to keep track of contacts that opt into messaging.
Add "is_opted_in" to campaign_contact table.
1 parent efdba41 commit 46ac8b6

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 = /sqlite/.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+
};

0 commit comments

Comments
 (0)