27 lines
924 B
TypeScript
27 lines
924 B
TypeScript
import { Knex } from "knex";
|
|
|
|
export default async (knex: Knex): Promise<void> => {
|
|
const addColumn = async (table: string, column: string, type: string) => {
|
|
if (!(await knex.schema.hasTable(table))) return;
|
|
if (!(await knex.schema.hasColumn(table, column))) {
|
|
await knex.schema.alterTable(table, (t) => (t as any)[type](column));
|
|
}
|
|
};
|
|
|
|
const dropColumn = async (table: string, column: string) => {
|
|
if (!(await knex.schema.hasTable(table))) return;
|
|
if (await knex.schema.hasColumn(table, column)) {
|
|
await knex.schema.alterTable(table, (t) => t.dropColumn(column));
|
|
}
|
|
};
|
|
|
|
const alterColumnType = async (table: string, column: string, type: string) => {
|
|
if (!(await knex.schema.hasTable(table))) return;
|
|
if (await knex.schema.hasColumn(table, column)) {
|
|
await knex.schema.alterTable(table, (t) => {
|
|
(t as any)[type](column).alter();
|
|
});
|
|
}
|
|
};
|
|
};
|