fix migrations
This commit is contained in:
@@ -22,17 +22,12 @@ until PGPASSWORD=$POSTGRES_PASSWORD psql -h db -U $POSTGRES_USER -d $POSTGRES_DB
|
|||||||
done
|
done
|
||||||
echo "PostgreSQL is up - executing command"
|
echo "PostgreSQL is up - executing command"
|
||||||
|
|
||||||
# Run migrations if they exist, otherwise initialize them
|
# Clean up existing migrations and initialize fresh
|
||||||
echo "Checking database migrations..."
|
echo "Cleaning up and initializing fresh migrations..."
|
||||||
if [ -d "migrations" ]; then
|
rm -rf migrations/versions/*
|
||||||
echo "Running existing migrations..."
|
|
||||||
flask db upgrade
|
|
||||||
else
|
|
||||||
echo "Initializing new migrations..."
|
|
||||||
flask db init
|
flask db init
|
||||||
flask db migrate -m "Initial migration"
|
flask db migrate -m "Initial migration"
|
||||||
flask db upgrade
|
flask db upgrade
|
||||||
fi
|
|
||||||
|
|
||||||
# Create default site settings if they don't exist
|
# Create default site settings if they don't exist
|
||||||
echo "Creating default site settings..."
|
echo "Creating default site settings..."
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
"""Add default admin user
|
|
||||||
|
|
||||||
Revision ID: add_default_admin_user
|
|
||||||
Revises: e7e4ff171f7a
|
|
||||||
Create Date: 2024-03-19 11:00:00.000000
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from sqlalchemy.sql import text
|
|
||||||
from werkzeug.security import generate_password_hash
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'add_default_admin_user'
|
|
||||||
down_revision = 'e7e4ff171f7a'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# Create default admin user
|
|
||||||
connection = op.get_bind()
|
|
||||||
|
|
||||||
# Generate password hash for 'q]H488h[8?.A'
|
|
||||||
password_hash = generate_password_hash('q]H488h[8?.A')
|
|
||||||
|
|
||||||
# Insert the admin user
|
|
||||||
connection.execute(
|
|
||||||
text("""
|
|
||||||
INSERT INTO "user" (
|
|
||||||
username, last_name, email, password_hash, is_admin,
|
|
||||||
is_active, position, created_at, preferred_view
|
|
||||||
) VALUES (
|
|
||||||
'Superadmin', 'Docupulse', 'administrator@docupulse.com',
|
|
||||||
:password_hash, true, true, 'Administrator', CURRENT_TIMESTAMP, 'grid'
|
|
||||||
)
|
|
||||||
"""),
|
|
||||||
{"password_hash": password_hash}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# Remove the default admin user
|
|
||||||
connection = op.get_bind()
|
|
||||||
connection.execute(
|
|
||||||
text("""
|
|
||||||
DELETE FROM "user"
|
|
||||||
WHERE email = 'administrator@docupulse.com'
|
|
||||||
""")
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user