Auto-update: Mon Aug 12 21:19:48 PDT 2024
This commit is contained in:
parent
bf6518c80e
commit
7f5cb9df77
2 changed files with 36 additions and 1 deletions
|
@ -20,8 +20,8 @@ from zoneinfo import ZoneInfo
|
||||||
from srtm import get_data
|
from srtm import get_data
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
import uuid
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from sqlalchemy import text, select, func, and_
|
from sqlalchemy import text, select, func, and_
|
||||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||||
|
|
35
sijapi/helpers/migrate_query_tracking_to_uuid.sh
Executable file
35
sijapi/helpers/migrate_query_tracking_to_uuid.sh
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# PostgreSQL connection details
|
||||||
|
DB_NAME="sij"
|
||||||
|
DB_USER="sij"
|
||||||
|
DB_PASSWORD="Synchr0!"
|
||||||
|
DB_HOST="localhost"
|
||||||
|
DB_PORT="5432"
|
||||||
|
|
||||||
|
# Function to execute SQL commands
|
||||||
|
execute_sql() {
|
||||||
|
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -c "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main script
|
||||||
|
echo "Starting migration of query_tracking table..."
|
||||||
|
|
||||||
|
# Enable uuid-ossp extension if not already enabled
|
||||||
|
execute_sql "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
|
||||||
|
|
||||||
|
# Add a new UUID column
|
||||||
|
execute_sql "ALTER TABLE query_tracking ADD COLUMN new_id UUID DEFAULT uuid_generate_v4();"
|
||||||
|
|
||||||
|
# Generate new UUIDs for all existing rows
|
||||||
|
execute_sql "UPDATE query_tracking SET new_id = uuid_generate_v4() WHERE new_id IS NULL;"
|
||||||
|
|
||||||
|
# Drop the old id column and rename the new one
|
||||||
|
execute_sql "ALTER TABLE query_tracking DROP COLUMN id;"
|
||||||
|
execute_sql "ALTER TABLE query_tracking RENAME COLUMN new_id TO id;"
|
||||||
|
|
||||||
|
# Set the new id column as primary key
|
||||||
|
execute_sql "ALTER TABLE query_tracking ADD PRIMARY KEY (id);"
|
||||||
|
|
||||||
|
echo "Migration completed successfully!"
|
||||||
|
|
Loading…
Reference in a new issue