- Updated database configuration to switch from SQLite to PostgreSQL, including changes to alembic.ini, Docker Compose, and environment settings. - Refactored application code to utilize PostgreSQL database adapters, ensuring compatibility with the new database structure. - Enhanced API routes and data handling to support the new database, including adjustments in data models and query logic. - Introduced new job processing mechanisms for full synchronization of AMO CRM entities, leveraging FastStream for background tasks. - Improved logging and error handling across the application to facilitate better monitoring and debugging. - Removed obsolete SQLite adapter files and migrations, streamlining the project structure for PostgreSQL integration.
113 lines
4.2 KiB
PowerShell
113 lines
4.2 KiB
PowerShell
# PowerShell script to run database migrations using Docker Compose
|
|
#
|
|
# Usage:
|
|
# .\scripts\run_migrations.ps1 [command]
|
|
#
|
|
# Commands:
|
|
# upgrade - Run all pending migrations (default)
|
|
# downgrade - Rollback one migration
|
|
# current - Show current migration version
|
|
# history - Show migration history
|
|
# create - Create a new migration (requires description)
|
|
#
|
|
|
|
param(
|
|
[Parameter(Position=0)]
|
|
[string]$Command = "upgrade",
|
|
|
|
[Parameter(Position=1)]
|
|
[string]$Description = ""
|
|
)
|
|
|
|
# Check if docker-compose is available
|
|
if (-not (Get-Command docker-compose -ErrorAction SilentlyContinue)) {
|
|
Write-Host "Error: docker-compose is not installed" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "===========================================================" -ForegroundColor Blue
|
|
Write-Host "Database Migration Tool" -ForegroundColor Blue
|
|
Write-Host "===========================================================" -ForegroundColor Blue
|
|
Write-Host ""
|
|
|
|
switch ($Command) {
|
|
"upgrade" {
|
|
Write-Host "Running migrations..." -ForegroundColor Green
|
|
docker-compose run --rm migrations
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "`n✓ Migrations completed successfully!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "`n✗ Migration failed!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
"downgrade" {
|
|
Write-Host "Rolling back one migration..." -ForegroundColor Yellow
|
|
docker-compose run --rm migrations sh -c "uv run alembic downgrade -1"
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "`n✓ Rollback completed!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "`n✗ Rollback failed!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
"current" {
|
|
Write-Host "Current migration version:" -ForegroundColor Blue
|
|
docker-compose run --rm migrations sh -c "uv run alembic current"
|
|
}
|
|
|
|
"history" {
|
|
Write-Host "Migration history:" -ForegroundColor Blue
|
|
docker-compose run --rm migrations sh -c "uv run alembic history"
|
|
}
|
|
|
|
"create" {
|
|
if ([string]::IsNullOrWhiteSpace($Description)) {
|
|
Write-Host "Error: Migration description required" -ForegroundColor Red
|
|
Write-Host "Usage: .\scripts\run_migrations.ps1 create `"your migration description`""
|
|
exit 1
|
|
}
|
|
Write-Host "Creating new migration: $Description" -ForegroundColor Green
|
|
docker-compose run --rm migrations sh -c "uv run alembic revision --autogenerate -m `"$Description`""
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host "`n✓ Migration created!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "`n✗ Migration creation failed!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
{ $_ -in "help", "--help", "-h" } {
|
|
Write-Host "Database Migration Tool" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Usage: .\scripts\run_migrations.ps1 [command] [args]"
|
|
Write-Host ""
|
|
Write-Host "Commands:"
|
|
Write-Host " upgrade Run all pending migrations (default)"
|
|
Write-Host " downgrade Rollback one migration"
|
|
Write-Host " current Show current migration version"
|
|
Write-Host " history Show migration history"
|
|
Write-Host " create Create a new migration"
|
|
Write-Host " help Show this help message"
|
|
Write-Host ""
|
|
Write-Host "Examples:"
|
|
Write-Host " .\scripts\run_migrations.ps1 # Run migrations"
|
|
Write-Host " .\scripts\run_migrations.ps1 upgrade # Run migrations"
|
|
Write-Host " .\scripts\run_migrations.ps1 downgrade # Rollback"
|
|
Write-Host " .\scripts\run_migrations.ps1 current # Show version"
|
|
Write-Host " .\scripts\run_migrations.ps1 history # Show history"
|
|
Write-Host " .\scripts\run_migrations.ps1 create `"add user table`" # Create migration"
|
|
}
|
|
|
|
default {
|
|
Write-Host "Error: Unknown command '$Command'" -ForegroundColor Red
|
|
Write-Host "Run '.\scripts\run_migrations.ps1 help' for usage information"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
|