Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only create sqlite DB file if DB_CONNECTION undefined or eq sqlite #120

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 37 additions & 33 deletions scripts/adonisjs-4-to-5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,42 @@ if [ -z "$DATA_DIR" ]; then
DATA_DIR="/data"
fi

# Define the path to your SQLite database file
db_file="$DATA_DIR/$DB_DATABASE.sqlite"

# Check if the database file exists
if [ ! -f "$db_file" ]; then
echo "Database file '$db_file' not found. An empty database will be created."
exit 0
fi

# Check if the "adonis_schema_versions" table exists and if the version is less than 2
version=$(sqlite3 "$db_file" "SELECT version FROM adonis_schema_versions LIMIT 1;" 2>/dev/null)
if [ -z "$version" ] || [ "$version" -lt 2 ]; then
# Table not found or version less than 2, proceed
echo "-- Starting database migration from AdonisJS v4 to v5 --"

# Check if the "adonis_schema" table exists
schema_exists=$(sqlite3 "$db_file" "SELECT name FROM sqlite_master WHERE type='table' AND name='adonis_schema';" 2>/dev/null)
if [ -n "$schema_exists" ]; then
# "adonis_schema" table exists, proceed

# Iterate through rows in the "name" column of "adonis_schema" and append "database/migrations" to each value
sqlite3 -batch "$db_file" "SELECT name FROM adonis_schema;" 2>/dev/null | while read -r old_value; do
new_value="database/migrations/$old_value"
echo "Updating value from '$old_value' to '$new_value'"

# Update the value in the database
sqlite3 "$db_file" "UPDATE adonis_schema SET name='$new_value' WHERE name='$old_value';" 2>/dev/null
done
else
echo "ERROR: Table 'adonis_schema' not found."
exit 1
# Check if $DB_CONNECTION is undefined or equals 'sqlite'
if [ -z "$DB_CONNECTION" ] || [ "$DB_CONNECTION" = "sqlite" ]; then

# Define the path to your SQLite database file
db_file="$DATA_DIR/$DB_DATABASE.sqlite"

# Check if the database file exists
if [ ! -f "$db_file" ]; then
echo "Database file '$db_file' not found. An empty database will be created."
exit 0
fi

# Check if the "adonis_schema_versions" table exists and if the version is less than 2
version=$(sqlite3 "$db_file" "SELECT version FROM adonis_schema_versions LIMIT 1;" 2>/dev/null)
if [ -z "$version" ] || [ "$version" -lt 2 ]; then
# Table not found or version less than 2, proceed
echo "-- Starting database migration from AdonisJS v4 to v5 --"

# Check if the "adonis_schema" table exists
schema_exists=$(sqlite3 "$db_file" "SELECT name FROM sqlite_master WHERE type='table' AND name='adonis_schema';" 2>/dev/null)
if [ -n "$schema_exists" ]; then
# "adonis_schema" table exists, proceed

# Iterate through rows in the "name" column of "adonis_schema" and append "database/migrations" to each value
sqlite3 -batch "$db_file" "SELECT name FROM adonis_schema;" 2>/dev/null | while read -r old_value; do
new_value="database/migrations/$old_value"
echo "Updating value from '$old_value' to '$new_value'"

# Update the value in the database
sqlite3 "$db_file" "UPDATE adonis_schema SET name='$new_value' WHERE name='$old_value';" 2>/dev/null
done
else
echo "ERROR: Table 'adonis_schema' not found."
exit 1
fi
# else
# echo "Version is greater than or equal to 2. Exiting script."
fi
# else
# echo "Version is greater than or equal to 2. Exiting script."
fi
Loading