This provides a set of [SQLAlchemy](https://www.sqlalchemy.org/) ORM models for the [ISPyB database](https://github.com/ispyb/ispyb-database/).
## Installation
Install from pypi [ispyb-models](https://pypi.org/project/ispyb-models):
```bash
pip install ispyb-models
```
## Basic Usage
```python
from ispyb import models
dataCollection = models.DataCollection(
...
)
ses.add(dataCollection)
ses.commit()
...
datacollections = (
ses.query(
models.DataCollection
).filter(models.DataCollection.dataCollectionId == 1)
).first()
)
```
## Generate a new version
To update the models you need to run the workflow `Update Models` through GitHub Actions panel.
This will create a new branch with models matching the latest DB release and create a pull request for merge this branch into main. Before merging there are some things you need to do:
- Make sure py-ispyb tests still pass with these new models
- Update `HISTORY.md` to reflect the changes
- Bump version number with `bump2version`
### ⚠️ Do not edit the output file yourself
**The resulting `_auto_db_schema.py` should not be edited** (other than automatic
formatting with `black` or sorting of imports with `isort`). All models are imported
into and accessed via the `__init__.py`. Any modifications, e.g. injecting additional
relationships between models should be done here.
### ⚠️ _[for local test]_ Manually update the DB schema
Checkout the specific tag for a given `ispyb-database` version:
```bash
$ git clone -b v1.18.1 https://github.com/ispyb/ispyb-database.git
$ # or, if you have an existing copy of the repository:
$ git checkout v1.18.1
```
Apply the schema patch in `patches/circular_references.patch` to avoid circular foreign key references:
```bash
$ patch -p1 < ispyb-models/patches/circular_references.patch
```
Then run the `ispyb-database` `build.sh` script to generate the database:
```bash
$ sh build.sh
```
Generate the models with [sqlacodegen](https://pypi.org/project/sqlacodegen/)
in `src/ispyb/models/`:
```bash
. generate_models.sh
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ispyb/ispyb-models",
"name": "ispyb-models",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "ISPyB,database,SQLAlchemy",
"author": "ISPyB",
"author_email": "py-ispyb-dev@esrf.fr",
"download_url": "https://files.pythonhosted.org/packages/ba/cd/02bc790e1bdaef3b2a9186dc41c3e65571f75ca554fdd85348e91c3a488b/ispyb-models-1.1.0.tar.gz",
"platform": null,
"description": "This provides a set of [SQLAlchemy](https://www.sqlalchemy.org/) ORM models for the [ISPyB database](https://github.com/ispyb/ispyb-database/).\n\n## Installation\n\nInstall from pypi [ispyb-models](https://pypi.org/project/ispyb-models):\n\n```bash\npip install ispyb-models\n```\n\n## Basic Usage\n\n```python\nfrom ispyb import models\n\ndataCollection = models.DataCollection(\n ...\n)\n\nses.add(dataCollection)\nses.commit()\n\n...\n\ndatacollections = (\n ses.query(\n models.DataCollection\n ).filter(models.DataCollection.dataCollectionId == 1)\n ).first()\n)\n```\n\n## Generate a new version\n\nTo update the models you need to run the workflow `Update Models` through GitHub Actions panel.\nThis will create a new branch with models matching the latest DB release and create a pull request for merge this branch into main. Before merging there are some things you need to do:\n\n- Make sure py-ispyb tests still pass with these new models\n- Update `HISTORY.md` to reflect the changes\n- Bump version number with `bump2version`\n\n### \u26a0\ufe0f Do not edit the output file yourself\n\n**The resulting `_auto_db_schema.py` should not be edited** (other than automatic\nformatting with `black` or sorting of imports with `isort`). All models are imported\ninto and accessed via the `__init__.py`. Any modifications, e.g. injecting additional\nrelationships between models should be done here.\n\n### \u26a0\ufe0f _[for local test]_ Manually update the DB schema\n\nCheckout the specific tag for a given `ispyb-database` version:\n\n```bash\n$ git clone -b v1.18.1 https://github.com/ispyb/ispyb-database.git\n$ # or, if you have an existing copy of the repository:\n$ git checkout v1.18.1\n```\n\nApply the schema patch in `patches/circular_references.patch` to avoid circular foreign key references:\n\n```bash\n$ patch -p1 < ispyb-models/patches/circular_references.patch\n```\n\nThen run the `ispyb-database` `build.sh` script to generate the database:\n\n```bash\n$ sh build.sh\n```\n\nGenerate the models with [sqlacodegen](https://pypi.org/project/sqlacodegen/)\nin `src/ispyb/models/`:\n\n```bash\n. generate_models.sh\n```\n",
"bugtrack_url": null,
"license": "Apache License, Version 2.0",
"summary": "SQLAlchemy ORM models for the ISPyB database",
"version": "1.1.0",
"split_keywords": [
"ispyb",
"database",
"sqlalchemy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "78c2eb23b7756db1f89a295b88dde67ecb52cf06d771542b514393f27628174f",
"md5": "cefaada2d9cfd53c9839b18c607099da",
"sha256": "6ac0281b9972589e8ab06ac219d0d2ae7e9faa210204da3a3bbf76a03c99c7fa"
},
"downloads": -1,
"filename": "ispyb_models-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cefaada2d9cfd53c9839b18c607099da",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 36439,
"upload_time": "2023-01-24T09:37:15",
"upload_time_iso_8601": "2023-01-24T09:37:15.473353Z",
"url": "https://files.pythonhosted.org/packages/78/c2/eb23b7756db1f89a295b88dde67ecb52cf06d771542b514393f27628174f/ispyb_models-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bacd02bc790e1bdaef3b2a9186dc41c3e65571f75ca554fdd85348e91c3a488b",
"md5": "8f60920259660e9c3644a98fc6d99d74",
"sha256": "8f6c4d323125efb3e248166a4b3d302abfd9b5e8dd1e1ba1b5716969e8a46ec2"
},
"downloads": -1,
"filename": "ispyb-models-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "8f60920259660e9c3644a98fc6d99d74",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 36905,
"upload_time": "2023-01-24T09:37:17",
"upload_time_iso_8601": "2023-01-24T09:37:17.262511Z",
"url": "https://files.pythonhosted.org/packages/ba/cd/02bc790e1bdaef3b2a9186dc41c3e65571f75ca554fdd85348e91c3a488b/ispyb-models-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-24 09:37:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "ispyb",
"github_project": "ispyb-models",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "sqlalchemy",
"specs": []
},
{
"name": "mysql-connector-python",
"specs": [
[
"==",
"8.0.29"
]
]
},
{
"name": "pytest",
"specs": []
}
],
"lcname": "ispyb-models"
}