summary refs log tree commit diff
path: root/bundle/scripts
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-07 21:43:38 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-09 23:28:27 +0200
commit29e88a440f2d9cc64ed7dff6f816d3fd0462acad (patch)
tree44efd285eae87074fa42b60e114702ab3bcbe4a7 /bundle/scripts
parentClean up commented out code in BaseClass (diff)
downloadserver-29e88a440f2d9cc64ed7dff6f816d3fd0462acad.tar.xz
Add migrations
Diffstat (limited to 'bundle/scripts')
-rwxr-xr-xbundle/scripts/db_migrations.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/bundle/scripts/db_migrations.sh b/bundle/scripts/db_migrations.sh
new file mode 100755
index 00000000..b0e1131c
--- /dev/null
+++ b/bundle/scripts/db_migrations.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+read -p "Enter migration filename: " FILENAME
+[ -f ".env" ] && (
+    mv .env .env.tmp
+    source .env.tmp
+)
+
+make_migration() {
+    echo "Creating migrations for $2"
+    mkdir "../util/src/migrations/$2"
+    npm run build clean logerrors pretty-errors
+    THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
+    THREADS=1 DATABASE="$1" DB_MIGRATE=a npx typeorm-ts-node-commonjs migration:generate "../util/src/migrations/$2/$FILENAME" -d ../util/src/util/Database.ts -p
+    npm run build clean logerrors pretty-errors
+    THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
+}
+
+npm i sqlite3
+make_migration "database.db" "sqlite"
+
+[ -z "$FC_DB_POSTGRES" ] || (
+    npm i pg
+    make_migration "$FC_DB_POSTGRES" "postgres"
+)
+
+[ -z "$FC_DB_MARIADB" ] || (
+    npm i mysql2
+    make_migration "$FC_DB_MARIADB" "mariadb"
+)
+
+[ -f ".env.tmp" ] && mv .env.tmp .env
+