mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 02:35:14 +00:00
Fixes db migration.
This commit is contained in:
parent
4b5235ae5d
commit
eb1c1d4165
3 changed files with 38 additions and 11 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -1,6 +1,7 @@
|
|||
.DS_Store
|
||||
**/__pycache__/
|
||||
**/.vscode/
|
||||
**/venv
|
||||
*.pyc
|
||||
node_modules/
|
||||
.history/
|
||||
|
|
@ -10,4 +11,10 @@ docker/Dockerfile DEV
|
|||
static/
|
||||
data/
|
||||
.next
|
||||
next-env.d.ts
|
||||
next-env.d.ts
|
||||
media/
|
||||
celerybeat-schedule*
|
||||
dump.rdb
|
||||
debugpy*
|
||||
uwsgi.sock
|
||||
package-lock.json
|
||||
|
|
@ -54,6 +54,7 @@ if [[ ! -f /etc/profile.d/dispatcharr.sh ]]; then
|
|||
echo "export DISPATCHARR_ENV=$DISPATCHARR_ENV" >> /etc/profile.d/dispatcharr.sh
|
||||
echo "export REDIS_HOST=$REDIS_HOST" >> /etc/profile.d/dispatcharr.sh
|
||||
echo "export REDIS_DB=$REDIS_DB" >> /etc/profile.d/dispatcharr.sh
|
||||
echo "export POSTGRES_DIR=$POSTGRES_DIR" >> /etc/profile.d/dispatcharr.sh
|
||||
fi
|
||||
|
||||
chmod +x /etc/profile.d/dispatcharr.sh
|
||||
|
|
|
|||
|
|
@ -3,14 +3,33 @@
|
|||
# Temporary migration from postgres in /data to /data/db. Can likely remove
|
||||
# some time in the future.
|
||||
if [ -e "/data/postgresql.conf" ]; then
|
||||
mv /data /db
|
||||
mkdir /data
|
||||
mv /db /data/
|
||||
echo "Migrating PostgreSQL data from /data to /data/db..."
|
||||
|
||||
# Create a temporary directory outside of /data
|
||||
mkdir -p /tmp/postgres_migration
|
||||
|
||||
# Move the PostgreSQL files to the temporary directory
|
||||
mv /data/* /tmp/postgres_migration/
|
||||
|
||||
# Create the target directory
|
||||
mkdir -p /data/db
|
||||
|
||||
# Move the files from temporary directory to the final location
|
||||
mv /tmp/postgres_migration/* /data/db/
|
||||
|
||||
# Clean up the temporary directory
|
||||
rmdir /tmp/postgres_migration
|
||||
|
||||
# Set proper ownership and permissions for PostgreSQL data directory
|
||||
chown -R postgres:postgres /data/db
|
||||
chmod 700 /data/db
|
||||
|
||||
echo "Migration completed successfully."
|
||||
fi
|
||||
|
||||
# Inwitialize PostgreSQL database
|
||||
# Initialize PostgreSQL database
|
||||
if [ -z "$(ls -A $POSTGRES_DIR)" ]; then
|
||||
echo_with_timestamp "Initializing PostgreSQL database..."
|
||||
echo "Initializing PostgreSQL database..."
|
||||
mkdir -p $POSTGRES_DIR
|
||||
chown -R postgres:postgres $POSTGRES_DIR
|
||||
chmod 700 $POSTGRES_DIR
|
||||
|
|
@ -26,7 +45,7 @@ if [ -z "$(ls -A $POSTGRES_DIR)" ]; then
|
|||
su - postgres -c "/usr/lib/postgresql/14/bin/pg_ctl -D ${POSTGRES_DIR} start -w -t 300 -o '-c port=${POSTGRES_PORT}'"
|
||||
# Wait for PostgreSQL to be ready
|
||||
until su - postgres -c "/usr/lib/postgresql/14/bin/pg_isready -h ${POSTGRES_HOST} -p ${POSTGRES_PORT}" >/dev/null 2>&1; do
|
||||
echo_with_timestamp "Waiting for PostgreSQL to be ready..."
|
||||
echo "Waiting for PostgreSQL to be ready..."
|
||||
sleep 1
|
||||
done
|
||||
|
||||
|
|
@ -35,11 +54,11 @@ if [ -z "$(ls -A $POSTGRES_DIR)" ]; then
|
|||
# Setup database if needed
|
||||
if ! su - postgres -c "psql -p ${POSTGRES_PORT} -tAc \"SELECT 1 FROM pg_database WHERE datname = '$POSTGRES_DB';\"" | grep -q 1; then
|
||||
# Create PostgreSQL database
|
||||
echo_with_timestamp "Creating PostgreSQL database..."
|
||||
echo "Creating PostgreSQL database..."
|
||||
su - postgres -c "createdb -p ${POSTGRES_PORT} ${POSTGRES_DB}"
|
||||
|
||||
# Create user, set ownership, and grant privileges
|
||||
echo_with_timestamp "Creating PostgreSQL user..."
|
||||
echo "Creating PostgreSQL user..."
|
||||
su - postgres -c "psql -p ${POSTGRES_PORT} -d ${POSTGRES_DB}" <<EOF
|
||||
DO \$\$
|
||||
BEGIN
|
||||
|
|
@ -49,11 +68,11 @@ BEGIN
|
|||
END
|
||||
\$\$;
|
||||
EOF
|
||||
echo_with_timestamp "Setting PostgreSQL user privileges..."
|
||||
echo "Setting PostgreSQL user privileges..."
|
||||
su postgres -c "/usr/lib/postgresql/14/bin/psql -p ${POSTGRES_PORT} -c \"ALTER DATABASE ${POSTGRES_DB} OWNER TO $POSTGRES_USER;\""
|
||||
su postgres -c "/usr/lib/postgresql/14/bin/psql -p ${POSTGRES_PORT} -c \"GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO $POSTGRES_USER;\""
|
||||
# Finished setting up PosgresSQL database
|
||||
echo_with_timestamp "PostgreSQL database setup complete."
|
||||
echo "PostgreSQL database setup complete."
|
||||
fi
|
||||
|
||||
kill $postgres_pid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue