Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New model definitions for version 2 API #64

Merged
merged 30 commits into from
Jul 13, 2021
Merged

Conversation

jonathansick
Copy link
Member

This PR contains revised SQLAlchemy models to power the new version 2 features of LTD Keeper.

These models are currently backwards compatible to aid adoption in current deployments.

New models include:

  • Organization (to power multi-tenant installations)
  • Tag (tags are associated with products using the producttags association table)
  • DashboardTemplate model to power template-based customization of version dashboards.

The organizations table is the basis of a multi-tenant installation.
These models allow us to create tags that have a many-to-many
relationship with Products (via the ProductTags association).

Tags are sequestered within an organization.
It should be the function rather than a constructed instance of datetime
which would effectively be the time when the app started up.

In practice, this default was overriden by the POST or PATCH handlers.
This model stores references to dashboard templates. These templates are
owned by an organization.
This relationship is currently nullable during the migration, but can be
changed to non-nullable later.
This column will replace Build.git_refs, where in practice we never use
the multiple ref feature.
This allows us to identify who uploaded a build.
This enumeration column allows us to classify the edition's kind, which
is useful information for edition dashboards.
Use the version from flask-sqlalchemy rather than the one directly from
sqlalchemy for consistency.
This is based on https://michaelcho.me/article/using-python-enums-in-sqlalchemy-models
The idea is that the native enum support will store the string value in
the database. It's easier in fact to just store the integer to the DB
and handle the enum at the Python level.
In the migration, apply a default value then make the column
non-nullable.
We do this by creating a default organization during the migration and then
updating all products to associate with that default organization.
To fall back to the original LTD API, the new_product() handler gets teh
first organization, which is the default organization created by the DB
migration for the v2 tables.

New installations of LTD, therefore, should use the v2 API in order to
use the organizations feature.
This matches how the v2 table migration automatically associates a
default organization with existing products, but otherwise the
organization feature isn't exposed by the v1 API.
Structlog requires text for the event now.
This order of type checking is correct because InEnum is a subclass of
int.
@jonathansick jonathansick marked this pull request as ready for review July 13, 2021 15:07
@jonathansick jonathansick merged commit d8b40e3 into master Jul 13, 2021
@jonathansick jonathansick deleted the u/jsickcodes/v2-tables branch July 13, 2021 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant