{"id":35448405,"url":"https://github.com/rodmena-limited/migretti","last_synced_at":"2026-01-13T19:56:33.475Z","repository":{"id":328722528,"uuid":"1115799580","full_name":"rodmena-limited/migretti","owner":"rodmena-limited","description":"sql migrations tool, done right for those of us don't rely on SqlAlchemy or Alembic. Migretti is a 10/10 tool for this use case. It is not just a   \"script runner\"; it is a fully featured migration engine with enterprise-grade safeguards (locking, auditing, transactional dry-runs) built-in. It is   perfectly suited for your applicaiton of any scale","archived":false,"fork":false,"pushed_at":"2025-12-15T18:19:47.000Z","size":75,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-17T12:29:10.710Z","etag":null,"topics":["alembic","alembic-migration","migration-tool","postgres-migration","postgres-migrations","postgresql","postgresql-database","postgresql-migration","postgresql-migrations","python-postgresql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rodmena-limited.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-13T15:23:17.000Z","updated_at":"2025-12-15T18:19:50.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rodmena-limited/migretti","commit_stats":null,"previous_names":["rodmena-limited/migretti"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/rodmena-limited/migretti","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodmena-limited%2Fmigretti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodmena-limited%2Fmigretti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodmena-limited%2Fmigretti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodmena-limited%2Fmigretti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodmena-limited","download_url":"https://codeload.github.com/rodmena-limited/migretti/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodmena-limited%2Fmigretti/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28398445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alembic","alembic-migration","migration-tool","postgres-migration","postgres-migrations","postgresql","postgresql-database","postgresql-migration","postgresql-migrations","python-postgresql"],"created_at":"2026-01-03T02:15:38.372Z","updated_at":"2026-01-13T19:56:33.470Z","avatar_url":"https://github.com/rodmena-limited.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MIGRETTI\n\nMigretti is a database migration tool designed for Python applications utilizing PostgreSQL. It provides a strict, SQL-first approach to schema management, ensuring atomicity, consistency, and traceability of database changes.\n\n## 1. INSTALLATION\n\nTo install Migretti, use pip:\n\n```bash\npip install migretti\n```\n\nDependencies include `psycopg[binary]`, `pyyaml`, `python-ulid`, `python-dotenv`, and `sqlparse`.\n\n## 2. GETTING STARTED\n\nInitialize a new migration project in your repository root:\n\n```bash\nmg init\n```\n\nThis command creates a `migrations/` directory and a `mg.yaml` configuration file.\n\n## 3. CONFIGURATION\n\nConfiguration is managed via the `mg.yaml` file. The tool also supports environment variable overrides and interpolation.\n\nExample `mg.yaml`:\n\n```yaml\ndatabase:\n  host: localhost\n  port: 5432\n  user: postgres\n  password: ${DB_PASSWORD}\n  dbname: my_database\n\nlock_id: 894321\n\nenvs:\n  production:\n    database:\n      host: db.prod.example.com\n      dbname: prod_db\n    lock_id: 999999\n\nhooks:\n  pre_apply: echo \"Backup starting...\"\n  post_apply: echo \"Migration complete.\"\n```\n\n**Environment Variables:**\n- `MG_DATABASE_URL`: Overrides connection settings (e.g., `postgresql://user:pass@host/db`).\n- `MG_ENV`: Selects the active environment profile (default: `default`).\n- `MG_LOCK_ID`: Overrides the advisory lock ID.\n\nEnvironment variable interpolation (e.g., `${VAR}`) is supported within `mg.yaml`.\n\n## 4. MIGRATION WORKFLOW\n\n### 4.1. Creating Migrations\n\nGenerate a new migration script:\n\n```bash\nmg create add_users_table\n```\n\nThis creates a file in `migrations/` with a unique ULID prefix. Edit the file to define the schema changes:\n\n```sql\n-- migration: Add Users Table\n-- id: 01H...\n\n-- migrate: up\nCREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT);\n\n-- migrate: down\nDROP TABLE users;\n```\n\n### 4.2. Applying Migrations\n\nApply all pending migrations:\n\n```bash\nmg apply\n```\n\nTo apply only the next pending migration:\n\n```bash\nmg up\n```\n\n### 4.3. Rolling Back\n\nRollback the last applied migration:\n\n```bash\nmg down\n```\n\nRollback multiple steps:\n\n```bash\nmg rollback 3\n```\n\n### 4.4. Status and Verification\n\nView the status of all migrations:\n\n```bash\nmg status\nmg list\n```\n\nVerify that applied migrations on disk match the database checksums:\n\n```bash\nmg verify\n```\n\n## 5. ADVANCED FEATURES\n\n### 5.1. Non-Transactional Migrations\n\nCertain operations, such as `CREATE INDEX CONCURRENTLY`, cannot run inside a transaction block. Use the `-- migrate: no-transaction` directive in your SQL file.\n\n```sql\n-- migrate: no-transaction\n-- migrate: up\nCREATE INDEX CONCURRENTLY idx_users ON users(name);\n```\n\nIf a non-transactional migration fails, Migretti records a \"failed\" status in the database. You must manually resolve the issue and then fix the migration state.\n\n### 5.2. Dry Run\n\nPreview the SQL to be executed without modifying the database:\n\n```bash\nmg apply --dry-run\n```\n\nFor transactional migrations, Migretti performs a \"Smart Dry Run,\" executing the SQL inside a transaction that is immediately rolled back to ensure validity.\n\n### 5.3. Data Seeding\n\nManage data seeding scripts in the `seeds/` directory.\n\nCreate a seed file:\n\n```bash\nmg seed create initial_data\n```\n\nRun all seeds:\n\n```bash\nmg seed\n```\n\n### 5.4. Hooks\n\nDefine shell commands to run before or after operations in `mg.yaml`:\n\n```yaml\nhooks:\n  pre_apply: ./scripts/backup_db.sh\n  post_rollback: ./scripts/notify_team.sh\n```\n\nSupported hooks: `pre_apply`, `post_apply`, `pre_rollback`, `post_rollback`.\n\n### 5.5. Migration Squashing\n\nCombine multiple pending migrations into a single file to maintain a clean history:\n\n```bash\nmg squash release_v1\n```\n\n### 5.6. Production Safety\n\nWhen running against environments named `prod`, `production`, or `live`, Migretti requires interactive confirmation unless the `--yes` flag is provided.\n\n### 5.7. Concurrency Control\n\nMigretti uses PostgreSQL advisory locks to ensure that only one migration process runs simultaneously, preventing race conditions in distributed deployment environments.\n\n### 5.8. Logging\n\nFor machine-readable output, use the JSON logging flag:\n\n```bash\nmg apply --json-log\n```\n\n## 6. LICENSE\n\nThis software is released under the **Apache License 2.0**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodmena-limited%2Fmigretti","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodmena-limited%2Fmigretti","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodmena-limited%2Fmigretti/lists"}