summary refs log tree commit diff
path: root/scripts/db_migrations.sh
blob: 9ec8230a57da98b4a87c53e6367a234db136b516 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh

if [ ! -z "$1" ]
then
    FILENAME="$1"
    echo "Using filename: $FILENAME"
else
    read -p "Enter migration filename: " FILENAME
fi

[ -f ".env" ] && (
    mv .env .env.tmp 2>/dev/null
    source .env.tmp 2>/dev/null
)
npm run build clean logerrors pretty-errors

make_migration() {
    echo "Creating migrations for $2"
    mkdir "src/util/migrations/$2" 2>/dev/null
#    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 "src/util/migrations/$2/$FILENAME" -d src/util/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 2>/dev/null