switch to knex migrations
This commit is contained in:
parent
e65706c6f2
commit
358984b474
|
@ -0,0 +1,23 @@
|
|||
// Update with your config settings.
|
||||
|
||||
/**
|
||||
* @type { Object.<string, import("knex").Knex.Config> }
|
||||
*/
|
||||
module.exports = {
|
||||
development: {
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: './jillo.sqlite'
|
||||
},
|
||||
useNullAsDefault: true,
|
||||
},
|
||||
|
||||
production: {
|
||||
// meh who needs postgres for now lole
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: './jillo.sqlite'
|
||||
},
|
||||
useNullAsDefault: true,
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.up = function(knex) {
|
||||
return knex.schema
|
||||
.createTable('scheduledSubscriptions', table => {
|
||||
table.string('name').primary();
|
||||
table.timestamp('next').defaultTo(knex.fn.now());
|
||||
})
|
||||
.createTable('subscriptions', table => {
|
||||
table.string('key')
|
||||
.references('name').inTable('scheduledSubscriptions');
|
||||
table.string('channel');
|
||||
table.string('guild').nullable();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.down = function(knex) {
|
||||
return knex.schema
|
||||
.dropTable('scheduledSubscriptions')
|
||||
.dropTable('subscriptions');
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.up = function(knex) {
|
||||
return knex.schema
|
||||
.createTable('counters', table => {
|
||||
table.string('key').notNullable();
|
||||
table.string('name').notNullable();
|
||||
table.string('emoji').notNullable();
|
||||
table.integer('value').defaultTo(0);
|
||||
table.string('channel').notNullable();
|
||||
table.string('guild').notNullable();
|
||||
table.string('message');
|
||||
table.string('messageTemplate');
|
||||
table.boolean('allowlistConsumer');
|
||||
table.boolean('allowlistProducer');
|
||||
})
|
||||
.createTable('counterUserLink', table => {
|
||||
table.string('key').references('key').inTable('counters');
|
||||
table.string('user').notNullable();
|
||||
table.boolean('producer');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.down = function(knex) {
|
||||
return knex.schema
|
||||
.dropTable('counters')
|
||||
.dropTable('counterUserLink');
|
||||
};
|
|
@ -3,7 +3,6 @@ import * as fs from 'fs';
|
|||
const { token } = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
|
||||
import * as path from 'path';
|
||||
import { initializeAnnouncements } from './lib/subscriptions';
|
||||
import { initTables } from './lib/db';
|
||||
import * as log from './lib/log';
|
||||
import chalk from 'chalk';
|
||||
import prettyBytes from 'pretty-bytes';
|
||||
|
@ -23,8 +22,6 @@ const bot = new Client({
|
|||
async function init() {
|
||||
log.nonsense('booting chip...');
|
||||
|
||||
await initTables();
|
||||
|
||||
log.nonsense('setting up connection...');
|
||||
|
||||
try {
|
||||
|
|
|
@ -32,32 +32,12 @@ export interface Counter {
|
|||
channel: string,
|
||||
guild: string,
|
||||
message?: string,
|
||||
allowlist: boolean
|
||||
messageTemplate?: string,
|
||||
allowlistConsumer: boolean,
|
||||
allowlistProducer: boolean
|
||||
}
|
||||
|
||||
export async function initTables() {
|
||||
await db.schema.createTableIfNotExists('scheduledSubscriptions', table => {
|
||||
table.string('name').primary();
|
||||
table.timestamp('next').defaultTo(db.fn.now());
|
||||
});
|
||||
await db.schema.createTableIfNotExists('subscriptions', table => {
|
||||
table.string('key')
|
||||
.references('name').inTable('scheduledSubscriptions');
|
||||
table.string('channel');
|
||||
table.string('guild').nullable();
|
||||
});
|
||||
await db.schema.createTableIfNotExists('counters', table => {
|
||||
table.string('key').notNullable();
|
||||
table.string('name').notNullable();
|
||||
table.string('emoji').notNullable();
|
||||
table.integer('value').defaultTo(0);
|
||||
table.string('channel').notNullable();
|
||||
table.string('guild').notNullable();
|
||||
table.string('message');
|
||||
table.boolean('allowlist');
|
||||
});
|
||||
await db.schema.createTableIfNotExists('counterUserLink', table => {
|
||||
table.string('key').references('key').inTable('counters');
|
||||
table.string('user').notNullable();
|
||||
});
|
||||
export interface CounterUserLink {
|
||||
key: string,
|
||||
user: string,
|
||||
producer: boolean
|
||||
}
|
Loading…
Reference in New Issue