{"id":16743418,"url":"https://github.com/gabfl/dbschema","last_synced_at":"2025-03-21T22:31:38.059Z","repository":{"id":45360483,"uuid":"99388262","full_name":"gabfl/dbschema","owner":"gabfl","description":"MySQL/PostgreSQL schema migrations made easy","archived":false,"fork":false,"pushed_at":"2023-05-09T00:23:19.000Z","size":90,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-01T10:21:37.836Z","etag":null,"topics":["database","db-schema","mysql","postgresql","schema-migrations","sql-migration"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabfl.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}},"created_at":"2017-08-05T00:13:00.000Z","updated_at":"2023-03-07T07:12:33.000Z","dependencies_parsed_at":"2024-10-28T11:53:20.058Z","dependency_job_id":null,"html_url":"https://github.com/gabfl/dbschema","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fdbschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fdbschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fdbschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fdbschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabfl","download_url":"https://codeload.github.com/gabfl/dbschema/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244165134,"owners_count":20409042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["database","db-schema","mysql","postgresql","schema-migrations","sql-migration"],"created_at":"2024-10-13T01:26:56.682Z","updated_at":"2025-03-21T22:31:37.628Z","avatar_url":"https://github.com/gabfl.png","language":"Python","readme":"# dbschema\n\n[![Pypi](https://img.shields.io/pypi/v/dbschema.svg)](https://pypi.org/project/dbschema)\n[![Build Status](https://github.com/gabfl/dbschema/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gabfl/dbschema/actions)\n[![codecov](https://codecov.io/gh/gabfl/dbschema/branch/main/graph/badge.svg)](https://codecov.io/gh/gabfl/dbschema)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/gabfl/dbschema/main/LICENSE)\n\n`dbschema` is a tool to run MySQL or PostgreSQL migrations automatically. Using a table, it keeps a state of previous migrations to avoid duplicates.\n\nFeatures:\n\n - Support for MySQL and PostgreSQL\n - Optional pre and post-migration queries (for example to update privileges)\n - Multiple migrations in multiple databases can be processed as one.\n\n## Installation\n\n### Install `dbschema`\n\n```bash\n# Install required packages\napt-get update\napt-get install --yes libpq-dev gcc python3-dev\n\npip3 install dbschema\n```\n\n### Create a config file\n\nCreate the file `~/.dbschema.yml` and add your databases configuration. [See example](dbschema_sample.yml)\n\n### Create migrations table\n\n`dbschema` uses a table called `migrations_applied` to keep track of migrations already applied to avoid duplication.\nSee the schema for [MySQL](schema/mysql.sql) or [PostgreSQL](schema/postgresql.sql).\n\n## Migrations folder structure\n\nFor each database, you need to have a migration path (setting `path` in the migration file).\n\nWithin that path you need to create one folder per migration. This folder must contain a file called `up.sql` with the SQL queries and optionally a file called `down.sql` for rollbacks.\n\n```\n/path/to/migrations/db1/\n|-- migration1/\n|   |-- up.sql\n|   |-- down.sql\n|-- migration2/\n|   |-- up.sql\n|...\n/path/to/migrations/db2/\n|-- migration1/\n|   |-- up.sql\n|-- migration2/\n|   |-- up.sql\n|   |-- down.sql\n|...\n```\n\n## Usage\n\n### Apply pending migrations\n\n```bash\ndbschema\n\n# or to specify a config file path\ndbschema --config /path/to/config.yml\n\n# or to migrate only a specific database\ndbschema --tag db1\n```\n\n### Rollback\n\n```bash\ndbschema --tag db1 --rollback migration1\n```\n\n## Example\n\n```bash\n$ dbschema\n  * Applying migrations for db1 (`test` on postgresql)\n    -\u003e Migration `migration1` applied\n    -\u003e Migration `migration2` applied\n    -\u003e Migration `migration3` applied\n  * Migrations applied\n  * Applying migrations for db2 (`test` on mysql)\n    -\u003e Migration `migration1` applied\n    -\u003e Migration `migration2` applied\n    -\u003e Migration `migration3` applied\n  * Migrations applied\n$\n$ dbschema --tag db2 --rollback migration1\n  * Rolling back mysql -\u003e `migration1`\n    -\u003e Migration `migration1` has been rolled back\n$\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabfl%2Fdbschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabfl%2Fdbschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabfl%2Fdbschema/lists"}