# Educationwarehouse's Migrate
[![PyPI - Version](https://img.shields.io/pypi/v/edwh-migrate.svg)](https://pypi.org/project/edwh-migrate)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/edwh-migrate.svg)](https://pypi.org/project/edwh-migrate)
-----
**Table of Contents**
- [Installation](#installation)
- [Documentation](#documentation)
- [License](#license)
## Installation
```console
pip install edwh-migrate
```
## Documentation
### Config: Environment variables
These variables can be set in the current environment or via `.env`:
* `MIGRATE_URI` (required): regular `postgres://user:password@host:port/database` or `sqlite:///path/to/database` URI
* `DATABASE_TO_RESTORE`: path to a (compressed) SQL file to restore. `.xz`,`.gz` and `.sql` are supported.
* `MIGRATE_CAT_COMMAND`: for unsupported compression formats, this command decompresses the file and produces sql on the
stdout.
* `SCHEMA_VERSION`: Used in case of schema versioning. Set by another process.
* `REDIS_HOST`: If set, all keys of the redis database 0 will be removed.
* `MIGRATE_TABLE`: name of the table where installed migrations are stored. Defaults to `ewh_implemented_features`.
* `FLAG_LOCATION`: when using schema versioned lock files, this directory is used to store the flags. Defaults to `/flags`.
* `CREATE_FLAG_LOCATION` (bool): should the directory above be created if it does not exist yet? Defaults to 0 (false).
* `SCHEMA`: (for postgres) set the default namespace (`search_path`). Defaults to `public`.
* `USE_TYPEDAL`: pass a TypeDAL instance to migrations instead of a regular pyDAL.
### Config: pyproject.toml
You can also set your config variables via the `[tool.migrate]` key in `pyproject.toml`.
First, these variables are loaded and then updated with variables from the environment.
This way, you can set static variables (the ones you want in git, e.g. the `migrate_table` name or path to the backup to
restore) in the toml, and keep private/dynamic vars in the environment (e.g. the database uri or schema version).
Example:
```toml
[tool.migrate]
migrate_uri = "" # filled in by .env
database-to-restore = "migrate/data/db_backup.sql"
# ...
```
### Creating a `migrations.py`
```python
from edwh_migrate import migration
@migration
def feature_1(db):
print("feature_1")
return True
@migration(requires=[feature_1]) # optional `requires` ensures previous migration(s) are installed
def functionalname_date_sequencenr(db: pydal.DAL):
db.executesql("""
CREATE TABLE ...
""")
db.commit()
return True
```
### Usage
When your configuration is set up properly and you have a file containing your migrations, you can simply run:
```bash
migrate
# or, to use a different name than migrations.py:
migrate path/to/my/migrate_file.py
```
## License
`edwh-migrate` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "edwh-migrate",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "database-migration, migrate, postgresql, pydal, schema-change",
"author": null,
"author_email": "Remco <remco@educationwarehouse.nl>",
"download_url": "https://files.pythonhosted.org/packages/4b/af/90c4923221977deae1881775e6156c916c6a167e99739b3136b7ac2dc713/edwh_migrate-0.8.1.tar.gz",
"platform": null,
"description": "# Educationwarehouse's Migrate\n\n[![PyPI - Version](https://img.shields.io/pypi/v/edwh-migrate.svg)](https://pypi.org/project/edwh-migrate)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/edwh-migrate.svg)](https://pypi.org/project/edwh-migrate)\n\n-----\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Documentation](#documentation)\n- [License](#license)\n\n## Installation\n\n```console\npip install edwh-migrate\n```\n\n## Documentation\n\n### Config: Environment variables\n\nThese variables can be set in the current environment or via `.env`:\n\n* `MIGRATE_URI` (required): regular `postgres://user:password@host:port/database` or `sqlite:///path/to/database` URI\n* `DATABASE_TO_RESTORE`: path to a (compressed) SQL file to restore. `.xz`,`.gz` and `.sql` are supported.\n* `MIGRATE_CAT_COMMAND`: for unsupported compression formats, this command decompresses the file and produces sql on the\n stdout.\n* `SCHEMA_VERSION`: Used in case of schema versioning. Set by another process.\n* `REDIS_HOST`: If set, all keys of the redis database 0 will be removed.\n* `MIGRATE_TABLE`: name of the table where installed migrations are stored. Defaults to `ewh_implemented_features`. \n* `FLAG_LOCATION`: when using schema versioned lock files, this directory is used to store the flags. Defaults to `/flags`.\n* `CREATE_FLAG_LOCATION` (bool): should the directory above be created if it does not exist yet? Defaults to 0 (false). \n* `SCHEMA`: (for postgres) set the default namespace (`search_path`). Defaults to `public`.\n* `USE_TYPEDAL`: pass a TypeDAL instance to migrations instead of a regular pyDAL.\n\n### Config: pyproject.toml\n\nYou can also set your config variables via the `[tool.migrate]` key in `pyproject.toml`.\nFirst, these variables are loaded and then updated with variables from the environment.\nThis way, you can set static variables (the ones you want in git, e.g. the `migrate_table` name or path to the backup to\nrestore) in the toml, and keep private/dynamic vars in the environment (e.g. the database uri or schema version).\n\nExample:\n\n```toml\n[tool.migrate]\nmigrate_uri = \"\" # filled in by .env\ndatabase-to-restore = \"migrate/data/db_backup.sql\"\n# ...\n```\n\n### Creating a `migrations.py`\n\n```python\nfrom edwh_migrate import migration\n\n@migration\ndef feature_1(db):\n print(\"feature_1\")\n return True\n\n\n@migration(requires=[feature_1]) # optional `requires` ensures previous migration(s) are installed\ndef functionalname_date_sequencenr(db: pydal.DAL):\n db.executesql(\"\"\"\n CREATE TABLE ...\n \"\"\")\n db.commit()\n return True\n\n```\n\n### Usage\n\nWhen your configuration is set up properly and you have a file containing your migrations, you can simply run:\n\n```bash\nmigrate\n# or, to use a different name than migrations.py:\nmigrate path/to/my/migrate_file.py\n```\n\n## License\n\n`edwh-migrate` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n",
"bugtrack_url": null,
"license": null,
"summary": "Helps migrating database schema changes using pydal. ",
"version": "0.8.1",
"project_urls": {
"Documentation": "https://github.com/educationwarehouse/migrate#readme",
"Issues": "https://github.com/educationwarehouse/migrate/issues",
"Source": "https://github.com/educationwarehouse/migrate"
},
"split_keywords": [
"database-migration",
" migrate",
" postgresql",
" pydal",
" schema-change"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "73eb1404220c2109b3bc33193cd530afcf600ac943826c798dff0454c486a4db",
"md5": "cd8e6a2b4fa08251214cda5092dc3916",
"sha256": "27fcf1e30a01ba82e1b9a76b5e7286545c01c6b6746b6f4a93a9d0e1d6965de7"
},
"downloads": -1,
"filename": "edwh_migrate-0.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cd8e6a2b4fa08251214cda5092dc3916",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 13358,
"upload_time": "2024-04-24T11:46:11",
"upload_time_iso_8601": "2024-04-24T11:46:11.704235Z",
"url": "https://files.pythonhosted.org/packages/73/eb/1404220c2109b3bc33193cd530afcf600ac943826c798dff0454c486a4db/edwh_migrate-0.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4baf90c4923221977deae1881775e6156c916c6a167e99739b3136b7ac2dc713",
"md5": "cc6fe9312ceb2cdc1cd137e98563ea2d",
"sha256": "d71f3a98e03b67812074e47a2e1a9d876439a65357af538a3fafa08078b85b4b"
},
"downloads": -1,
"filename": "edwh_migrate-0.8.1.tar.gz",
"has_sig": false,
"md5_digest": "cc6fe9312ceb2cdc1cd137e98563ea2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 31240,
"upload_time": "2024-04-24T11:46:13",
"upload_time_iso_8601": "2024-04-24T11:46:13.672077Z",
"url": "https://files.pythonhosted.org/packages/4b/af/90c4923221977deae1881775e6156c916c6a167e99739b3136b7ac2dc713/edwh_migrate-0.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-24 11:46:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "educationwarehouse",
"github_project": "migrate#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "edwh-migrate"
}