From dd408a52ff464d2b52e6ee46167a6110d20e6e3f Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 16 Aug 2022 08:24:48 +0200 Subject: [PATCH] Down and upgrade script for 0046-messages_tables --- database/migrations/0046-messages_tables.ts | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 database/migrations/0046-messages_tables.ts diff --git a/database/migrations/0046-messages_tables.ts b/database/migrations/0046-messages_tables.ts new file mode 100644 index 000000000..59b7df803 --- /dev/null +++ b/database/migrations/0046-messages_tables.ts @@ -0,0 +1,24 @@ +/** + * MIGRATION TO CREATE THE MESSAGES TABLES + * + * This migration creates the `messages` tables in the `community_server` database (`gradido_community`). + * This is done to keep all data in the same place and is to be understood in conjunction with the next migration + * `0046-messages_tables` which will fill the tables with the existing data + */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(` + CREATE TABLE IF NOT EXISTS \`messages\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`contribution_id\` int(10) unsigned NOT NULL, + \`user_id\` int(10) unsigned NOT NULL, + \`message\` varchar(2000) NOT NULL, + \`created_at\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (\`id\`), + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + `) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(`DROP TABLE IF EXISTS \`messages\`;`) +}