Name | atlas-provider-sqlalchemy JSON |
Version |
0.2.2
JSON |
| download |
home_page | None |
Summary | Load sqlalchemy models into an Atlas project. |
upload_time | 2024-05-21 08:29:19 |
maintainer | None |
docs_url | None |
author | Your Name |
requires_python | <4.0,>=3.8 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# atlas-provider-sqlalchemy
Load [SQLAlchemy](https://www.sqlalchemy.org/) models into an [Atlas](https://atlasgo.io) project.
### Use-cases
1. **Declarative migrations** - use a Terraform-like `atlas schema apply --env sqlalchemy` to apply your SQLAlchemy schema to the database.
2. **Automatic migration planning** - use `atlas migrate diff --env sqlalchemy` to automatically plan a migration from the current database version to the SQLAlchemy schema.
### Installation
Install Atlas from macOS or Linux by running:
```bash
curl -sSf https://atlasgo.sh | sh
```
See [atlasgo.io](https://atlasgo.io/getting-started#installation) for more installation options.
Install the provider by running:
```bash
# The Provider works by importing your SQLAlchemy models and extracting the schema from them.
# Therefore, you will need to run the provider from within your project's Python environment.
pip install atlas-provider-sqlalchemy
```
#### Standalone
If all of your SQLAlchemy models exist in a single package,
you can use the provider directly to load your SQLAlchemy schema into Atlas.
In your project directory, create a new file named `atlas.hcl` with the following contents:
```hcl
data "external_schema" "sqlalchemy" {
program = [
"atlas-provider-sqlalchemy",
"--path", "./path/to/models",
"--dialect", "mysql" // mariadb | postgresql | sqlite | mssql
]
}
env "sqlalchemy" {
src = data.external_schema.sqlalchemy.url
dev = "docker://mysql/8/dev"
migration {
dir = "file://migrations"
}
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
```
#### As Python Script
If you want to use the provider as a python script, you can use the provider as follows:
Create a new file named `load_models.py` with the following contents:
```python
# import all models
from models import User, Task
from atlas_provider_sqlalchemy.ddl import print_ddl
print_ddl("mysql", [User, Task])
```
Next, in your project directory, create a new file named `atlas.hcl` with the following contents:
```hcl
data "external_schema" "sqlalchemy" {
program = [
"python",
"load_models.py"
]
}
env "sqlalchemy" {
src = data.external_schema.sqlalchemy.url
dev = "docker://mysql/8/dev"
migration {
dir = "file://migrations"
}
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
```
### Usage
Once you have the provider installed, you can use it to apply your SQLAlchemy schema to the database:
#### Apply
You can use the `atlas schema apply` command to plan and apply a migration of your database to your current SQLAlchemy schema.
This works by inspecting the target database and comparing it to the SQLAlchemy schema and creating a migration plan.
Atlas will prompt you to confirm the migration plan before applying it to the database.
```bash
atlas schema apply --env sqlalchemy -u "mysql://root:password@localhost:3306/mydb"
```
Where the `-u` flag accepts the [URL](https://atlasgo.io/concepts/url) to the
target database.
#### Diff
Atlas supports a [version migration](https://atlasgo.io/concepts/declarative-vs-versioned#versioned-migrations)
workflow, where each change to the database is versioned and recorded in a migration file. You can use the
`atlas migrate diff` command to automatically generate a migration file that will migrate the database
from its latest revision to the current SQLAlchemy schema.
```bash
atlas migrate diff --env sqlalchemy
````
### Supported Databases
The provider supports the following databases:
* MySQL
* MariaDB
* PostgreSQL
* SQLite
* Microsoft SQL Server
### Credit
The code in this repository is based on [noamtamir/atlas-provider-sqlalchemy](https://github.com/noamtamir/atlas-provider-sqlalchemy).
### Issues
Please report any issues or feature requests in the [ariga/atlas](https://github.com/ariga/atlas/issues) repository.
### License
This project is licensed under the [Apache License 2.0](LICENSE).
Raw data
{
"_id": null,
"home_page": null,
"name": "atlas-provider-sqlalchemy",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Your Name",
"author_email": "you@example.com",
"download_url": "https://files.pythonhosted.org/packages/60/fd/ab87ead1495448869ac30a27f17927938bd7f098d0256d0c7a2104da3697/atlas_provider_sqlalchemy-0.2.2.tar.gz",
"platform": null,
"description": "# atlas-provider-sqlalchemy\n\nLoad [SQLAlchemy](https://www.sqlalchemy.org/) models into an [Atlas](https://atlasgo.io) project.\n\n### Use-cases\n1. **Declarative migrations** - use a Terraform-like `atlas schema apply --env sqlalchemy` to apply your SQLAlchemy schema to the database.\n2. **Automatic migration planning** - use `atlas migrate diff --env sqlalchemy` to automatically plan a migration from the current database version to the SQLAlchemy schema.\n\n### Installation\n\nInstall Atlas from macOS or Linux by running:\n```bash\ncurl -sSf https://atlasgo.sh | sh\n```\n\nSee [atlasgo.io](https://atlasgo.io/getting-started#installation) for more installation options.\n\nInstall the provider by running:\n```bash\n# The Provider works by importing your SQLAlchemy models and extracting the schema from them.\n# Therefore, you will need to run the provider from within your project's Python environment.\npip install atlas-provider-sqlalchemy\n```\n\n#### Standalone \n\nIf all of your SQLAlchemy models exist in a single package, \nyou can use the provider directly to load your SQLAlchemy schema into Atlas.\n\nIn your project directory, create a new file named `atlas.hcl` with the following contents:\n\n```hcl\ndata \"external_schema\" \"sqlalchemy\" {\n program = [\n \"atlas-provider-sqlalchemy\",\n \"--path\", \"./path/to/models\",\n \"--dialect\", \"mysql\" // mariadb | postgresql | sqlite | mssql\n ]\n}\n\nenv \"sqlalchemy\" {\n src = data.external_schema.sqlalchemy.url\n dev = \"docker://mysql/8/dev\"\n migration {\n dir = \"file://migrations\"\n }\n format {\n migrate {\n diff = \"{{ sql . \\\" \\\" }}\"\n }\n }\n}\n```\n\n#### As Python Script \n\nIf you want to use the provider as a python script, you can use the provider as follows:\n\nCreate a new file named `load_models.py` with the following contents:\n\n```python\n# import all models\nfrom models import User, Task\nfrom atlas_provider_sqlalchemy.ddl import print_ddl\nprint_ddl(\"mysql\", [User, Task])\n```\n\nNext, in your project directory, create a new file named `atlas.hcl` with the following contents:\n\n```hcl\ndata \"external_schema\" \"sqlalchemy\" {\n program = [\n \"python\",\n \"load_models.py\"\n ]\n}\n\nenv \"sqlalchemy\" {\n src = data.external_schema.sqlalchemy.url\n dev = \"docker://mysql/8/dev\"\n migration {\n dir = \"file://migrations\"\n }\n format {\n migrate {\n diff = \"{{ sql . \\\" \\\" }}\"\n }\n }\n}\n```\n\n### Usage\n\nOnce you have the provider installed, you can use it to apply your SQLAlchemy schema to the database:\n\n#### Apply\n\nYou can use the `atlas schema apply` command to plan and apply a migration of your database to your current SQLAlchemy schema.\nThis works by inspecting the target database and comparing it to the SQLAlchemy schema and creating a migration plan.\nAtlas will prompt you to confirm the migration plan before applying it to the database.\n\n```bash\natlas schema apply --env sqlalchemy -u \"mysql://root:password@localhost:3306/mydb\"\n```\nWhere the `-u` flag accepts the [URL](https://atlasgo.io/concepts/url) to the\ntarget database.\n\n#### Diff\n\nAtlas supports a [version migration](https://atlasgo.io/concepts/declarative-vs-versioned#versioned-migrations) \nworkflow, where each change to the database is versioned and recorded in a migration file. You can use the\n`atlas migrate diff` command to automatically generate a migration file that will migrate the database\nfrom its latest revision to the current SQLAlchemy schema.\n\n```bash\natlas migrate diff --env sqlalchemy \n````\n\n### Supported Databases\n\nThe provider supports the following databases:\n* MySQL\n* MariaDB\n* PostgreSQL\n* SQLite\n* Microsoft SQL Server\n\n### Credit\n\nThe code in this repository is based on [noamtamir/atlas-provider-sqlalchemy](https://github.com/noamtamir/atlas-provider-sqlalchemy).\n\n### Issues\n\nPlease report any issues or feature requests in the [ariga/atlas](https://github.com/ariga/atlas/issues) repository.\n\n### License\n\nThis project is licensed under the [Apache License 2.0](LICENSE).\n",
"bugtrack_url": null,
"license": null,
"summary": "Load sqlalchemy models into an Atlas project.",
"version": "0.2.2",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7c9f29f5f891b70ab617fa314118451dbc98c745134514e8c5507c120a4eceb0",
"md5": "134d374dd8868752cccd65c5ab9a0b80",
"sha256": "0b89a5d2ed6b11376e52a78c2d886adb817fe9235a2037e2012af4b895fddae2"
},
"downloads": -1,
"filename": "atlas_provider_sqlalchemy-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "134d374dd8868752cccd65c5ab9a0b80",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 9200,
"upload_time": "2024-05-21T08:29:18",
"upload_time_iso_8601": "2024-05-21T08:29:18.038745Z",
"url": "https://files.pythonhosted.org/packages/7c/9f/29f5f891b70ab617fa314118451dbc98c745134514e8c5507c120a4eceb0/atlas_provider_sqlalchemy-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "60fdab87ead1495448869ac30a27f17927938bd7f098d0256d0c7a2104da3697",
"md5": "39a6a7b5155919b39bf45c171f4bb9cf",
"sha256": "340edc2f5b994c1f6469dae39f4d000c676772f5711dea2aff58f86b73a0d79c"
},
"downloads": -1,
"filename": "atlas_provider_sqlalchemy-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "39a6a7b5155919b39bf45c171f4bb9cf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 7799,
"upload_time": "2024-05-21T08:29:19",
"upload_time_iso_8601": "2024-05-21T08:29:19.156027Z",
"url": "https://files.pythonhosted.org/packages/60/fd/ab87ead1495448869ac30a27f17927938bd7f098d0256d0c7a2104da3697/atlas_provider_sqlalchemy-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-21 08:29:19",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "atlas-provider-sqlalchemy"
}