aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/adonisjs-4-to-5.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/scripts/adonisjs-4-to-5.sh b/scripts/adonisjs-4-to-5.sh
new file mode 100644
index 0000000..ccb5c9f
--- /dev/null
+++ b/scripts/adonisjs-4-to-5.sh
@@ -0,0 +1,50 @@
1#!/bin/bash
2
3# THIS SCRIPT IS USED TO MIGRATE FROM ADONISJS V4 TO ADONISJS V5
4# IT SHOULD BE RUN BEFORE RUNNING THE SERVER
5
6# Check if DB_DATABASE is undefined or empty, and set a default value if necessary
7if [ -z "$DB_DATABASE" ]; then
8 DB_DATABASE="ferdium"
9fi
10
11# Check if DATA_DIR is undefined or empty, and set a default value if necessary
12if [ -z "$DATA_DIR" ]; then
13 DATA_DIR="/data"
14fi
15
16# Define the path to your SQLite database file
17db_file="$DATA_DIR/$DB_DATABASE.sqlite"
18
19# Check if the database file exists
20if [ ! -f "$db_file" ]; then
21 echo "Database file '$db_file' not found. An empty database will be created."
22 exit 0
23fi
24
25# Check if the "adonis_schema_versions" table exists and if the version is less than 2
26version=$(sqlite3 "$db_file" "SELECT version FROM adonis_schema_versions LIMIT 1;" 2>/dev/null)
27if [ -z "$version" ] || [ "$version" -lt 2 ]; then
28 # Table not found or version less than 2, proceed
29 echo "-- Starting database migration from AdonisJS v4 to v5 --"
30
31 # Check if the "adonis_schema" table exists
32 schema_exists=$(sqlite3 "$db_file" "SELECT name FROM sqlite_master WHERE type='table' AND name='adonis_schema';" 2>/dev/null)
33 if [ -n "$schema_exists" ]; then
34 # "adonis_schema" table exists, proceed
35
36 # Iterate through rows in the "name" column of "adonis_schema" and append "database/migrations" to each value
37 sqlite3 -batch "$db_file" "SELECT name FROM adonis_schema;" 2>/dev/null | while read -r old_value; do
38 new_value="database/migrations/$old_value"
39 echo "Updating value from '$old_value' to '$new_value'"
40
41 # Update the value in the database
42 sqlite3 "$db_file" "UPDATE adonis_schema SET name='$new_value' WHERE name='$old_value';" 2>/dev/null
43 done
44 else
45 echo "ERROR: Table 'adonis_schema' not found."
46 exit 1
47 fi
48# else
49 # echo "Version is greater than or equal to 2. Exiting script."
50fi