{"id":23690163,"url":"https://github.com/aminehmida/sqlmigman","last_synced_at":"2025-08-01T16:09:01.880Z","repository":{"id":150071062,"uuid":"135892771","full_name":"aminehmida/sqlmigman","owner":"aminehmida","description":"Tool to manage database schema migration","archived":false,"fork":false,"pushed_at":"2018-07-06T17:06:54.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-29T08:05:32.230Z","etag":null,"topics":["devops","migration","mysql","postgres","postgresql","sql","upgrade"],"latest_commit_sha":null,"homepage":"","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/aminehmida.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2018-06-03T10:01:35.000Z","updated_at":"2018-07-30T16:33:35.000Z","dependencies_parsed_at":"2023-06-04T19:45:19.282Z","dependency_job_id":null,"html_url":"https://github.com/aminehmida/sqlmigman","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aminehmida/sqlmigman","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminehmida%2Fsqlmigman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminehmida%2Fsqlmigman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminehmida%2Fsqlmigman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminehmida%2Fsqlmigman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aminehmida","download_url":"https://codeload.github.com/aminehmida/sqlmigman/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminehmida%2Fsqlmigman/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268257077,"owners_count":24221054,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["devops","migration","mysql","postgres","postgresql","sql","upgrade"],"created_at":"2024-12-30T01:59:40.033Z","updated_at":"2025-08-01T16:09:01.871Z","avatar_url":"https://github.com/aminehmida.png","language":"Python","readme":"# SQL (Mig)ration (Man)ager [![Build Status](https://travis-ci.com/aminehmida/sqlmigman.svg?branch=master)](https://travis-ci.com/aminehmida/sqlmigman)\n\nHighly extensible tool to manage SQL database schema migration. Can support MySql/Postgrasql ...\n\n**Note:** This is still an alpha version. Expect dragons!\n\n## Installing\n\nStart by cloning this project. No external dependency was used. Tested and working in python 2.7 and 3.6\n\n## Getting Started\n\nSqlMigMan is used to manage database schema updates. It is highly extensible because it uses a template syntax to do the following:\n\n1. Match update scripts file name with a regexp. You can use `(\\d+)\\D*\\.sql` to match `\u003cversion\u003e\u003cname\u003e.sql` and `\u003cversion\u003e-\u003cname\u003e.sql` at the same time for example. Vesion is matched with `()`\n2. Extract existing database schema version\n3. Apply update scripts higher then current schema with order (from low to high)\n4. Update the schema version after each successful update\n\nCheck provided config example `sqlmigman.cfg.example` and customise for your needs then copy config to same working dir, `/etc/` or `/usr/local/etc/`. Finally, launch with `python launch.py`\n\n### Example of config file to manage MySQL database updates:\n\n```\nscripts_dir = /path/to/update/scripts\nscript_regexp = (\\d+)\\D*\\.sql\napply_cmd = mysql $(-u %user% )$(-p %password% )$(-h %host% )%db% \u003c %script%\nversion_cmd = mysql $(-u %user% )$(-p %password% )$(-h %host% )%db% -e \"SELECT version FROM version\"\nversion_update_cmd = mysql $(-u %user% )$(-p %password% )$(-h %host% )%db% -e \"UPDATE version SET version=%version%\"\n```\n\n**Note:** All configs can be passed using command line. Type `python launch.py -h` to find matching arguments names:\n\n```\nusage: launch.py [-h] [--mig-dir MIG_DIR] [--sql-host SQL_HOST]\n                 [--sql-user SQL_USER] [--sql-password SQL_PASSWORD]\n                 [--sql-db SQL_DB] [--continue-on-fail CONTINUE_ON_FAIL]\n                 [--mig-cmd MIG_CMD] [--mig-regexp MIG_REGEXP]\n                 [--mig-update-cmd MIG_UPDATE_CMD]\n                 [--mig-version-cmd MIG_VERSION_CMD]\n\nDatabase schema upgrade manager.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --mig-dir MIG_DIR, -d MIG_DIR\n                        Directory where .sql file are located\n  --sql-host SQL_HOST, -s SQL_HOST\n                        Sql server host or ip address.\n  --sql-user SQL_USER, -u SQL_USER\n                        Database user name.\n  --sql-password SQL_PASSWORD, -p SQL_PASSWORD\n                        Database user password.\n  --sql-db SQL_DB, -n SQL_DB\n                        Database name\n  --continue-on-fail CONTINUE_ON_FAIL, -f CONTINUE_ON_FAIL\n                        Continue upgrade when intermediary failure is\n                        detected.\n  --mig-cmd MIG_CMD, -c MIG_CMD\n                        Migration command template\n  --mig-regexp MIG_REGEXP, -r MIG_REGEXP\n                        Regular expression used to match and extract schema\n                        version from .sql upgrade script. Default will match\n                        \u003cversion\u003e\u003cname\u003e.sql\n  --mig-update-cmd MIG_UPDATE_CMD, -t MIG_UPDATE_CMD\n                        This command will be run when all update script are\n                        applied with success. Use a syntax simular to --arg-\n                        cmd with addition of %version% variablethat contains\n                        version of the latest script applied\n  --mig-version-cmd MIG_VERSION_CMD, -v MIG_VERSION_CMD\n                        This command will be run to extract current database\n                        schema version. Same syntax as --mig-cmd\n```\n\n### Command templates:\nYou can use two types of command template formats:\n\n- Simple format `%var_name%`: This will be simply replaced with `var_name` if defined. If `var_name` is not defined `%var_name%` will be removed from the template.\n\n- Composite format `$(cont1 %var_name% const2)`: with this format`$(` and `)` will be removed, `%var_name%` will be replaced with its value and `const1`/`const2` are kept as is.\n\n## Running tests\n\nStart by installing `requirements_dev.txt` and run `pycodestyle --show-pep8 *.py ./sqlmigman/*.py ./tests/*.py; pytest -vv --showlocals ./tests` to execute style check and unit tests.\n\n## TODO:\n- Add support for environment variables.\n- Add `--dry-run`\n- Build docker container\n- Add `--config` flag\n- Automate style and unit tests\n- Add more unit tests\n- Add integration tests with docker\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminehmida%2Fsqlmigman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faminehmida%2Fsqlmigman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminehmida%2Fsqlmigman/lists"}