Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Create SQLAlchemy ORM models for CliDE CDMS #9

@isedwards

Description

@isedwards

This issue will begin to add support for CliDE, a Climate Data Management System (CDMS) used in the Pacific.

You will need PostgreSQL installed and then to restore the CliDE SQL DDL file here.

I don’t think it is possible to use automap to write the model classes to a .py file. However, it is possible to do this with sqlacodegen. This will create all of the classes automatically and will also create code to represent all of the relationships between tables.

The final step for the first task is to create a fork of pyopencdms, add the generated models to /opencdms/models/clide.py and then submit a pull request.

I rough outline of the commands is below:

# Use psql to create a database called clideDB (this can be owened by the `postgres` user
$ git clone https://github.com/opencdms/opencdms-test-data.git
$ psql clideDB < opencdms-test-data/schemas/clide/clidedb_schema.sql

You’ll need to fork https://github.com/opencdms/pyopencdms so that you can push your changes

$ git clone https://github.com/<your_username>/pyopencdms.git   # (your fork)
$ cd pyopencdms
$ pip3 install sqlacodegen psycopg2
$ sqlacodegen postgresql+psycopg2://localhost/clideDB > opencdms/models/clide.py 
$ git add .
$ git commit -m "SQLAlchemy models for CliDE"
$ git push origin
Then a pull request…

In addition, verify the code it generates:

We have 44 tables and therefore at least 44 models to be generated. Try to validate the generated code against alembic and perform some manual checks for at least 3 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions