-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API - break out ownership and person in the db (#204)
* API - break out ownership and person in the db Signed-off-by: Kial Jinnah <[email protected]> * tweak Signed-off-by: Kial Jinnah <[email protected]> * fix UI test Signed-off-by: Kial Jinnah <[email protected]> * UI test / lint fixes Signed-off-by: Kial Jinnah <[email protected]> * Updated pm tests, added statement id interest conncected people mapping Signed-off-by: Kial Jinnah <[email protected]> * PR comment update Signed-off-by: Kial Jinnah <[email protected]> --------- Signed-off-by: Kial Jinnah <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,219 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
btr-api/migrations/versions/20240924_0922_8d8279a86def_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
"""empty message | ||
Revision ID: 8d8279a86def | ||
Revises: 8850fb7d527b | ||
Create Date: 2024-09-24 09:22:07.352266 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '8d8279a86def' | ||
down_revision = '8850fb7d527b' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('person', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('statement_id', sa.Uuid(), nullable=False), | ||
sa.Column('person_json', postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.Column('birthdate', sa.Date(), nullable=True), | ||
sa.Column('is_public', sa.Boolean(), nullable=False), | ||
sa.Column('last_notification_type', sa.Enum('ADDING_ADULT', 'ADDING_MINOR', 'UPDATING_MINOR_PUBLIC', name='emailtype'), nullable=True), | ||
sa.Column('last_notification_datetime', sa.DateTime(), nullable=True), | ||
sa.Column('version', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('statement_id'), | ||
sqlite_autoincrement=True | ||
) | ||
op.create_table('person_history', | ||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False), | ||
sa.Column('statement_id', sa.Uuid(), autoincrement=False, nullable=False), | ||
sa.Column('person_json', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=False), | ||
sa.Column('birthdate', sa.Date(), autoincrement=False, nullable=True), | ||
sa.Column('is_public', sa.Boolean(), autoincrement=False, nullable=False), | ||
sa.Column('last_notification_type', sa.Enum('ADDING_ADULT', 'ADDING_MINOR', 'UPDATING_MINOR_PUBLIC', name='emailtype'), autoincrement=False, nullable=True), | ||
sa.Column('last_notification_datetime', sa.DateTime(), autoincrement=False, nullable=True), | ||
sa.Column('version', sa.Integer(), autoincrement=False, nullable=False), | ||
sa.Column('changed', sa.DateTime(), nullable=True), | ||
sa.PrimaryKeyConstraint('id', 'version'), | ||
sqlite_autoincrement=True | ||
) | ||
op.create_table('ownership', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('statement_id', sa.Uuid(), nullable=False), | ||
sa.Column('ownership_json', postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.Column('person_id', sa.Integer(), nullable=True), | ||
sa.Column('submission_id', sa.Integer(), nullable=True), | ||
sa.Column('version', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['person_id'], ['person.id'], ), | ||
sa.ForeignKeyConstraint(['submission_id'], ['submission.id'], ), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('statement_id'), | ||
sqlite_autoincrement=True | ||
) | ||
op.create_table('ownership_history', | ||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False), | ||
sa.Column('statement_id', sa.Uuid(), autoincrement=False, nullable=False), | ||
sa.Column('ownership_json', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=False), | ||
sa.Column('person_id', sa.Integer(), autoincrement=False, nullable=True), | ||
sa.Column('submission_id', sa.Integer(), autoincrement=False, nullable=True), | ||
sa.Column('version', sa.Integer(), autoincrement=False, nullable=False), | ||
sa.Column('changed', sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(['person_id'], ['person.id'], ), | ||
sa.ForeignKeyConstraint(['submission_id'], ['submission.id'], ), | ||
sa.PrimaryKeyConstraint('id', 'version'), | ||
sqlite_autoincrement=True | ||
) | ||
with op.batch_alter_table('submission', schema=None) as batch_op: | ||
batch_op.alter_column('type', | ||
existing_type=postgresql.ENUM('other', 'standard', name='submissiontype'), | ||
nullable=False) | ||
batch_op.alter_column('submitted_datetime', | ||
existing_type=postgresql.TIMESTAMP(timezone=True), | ||
type_=sa.DateTime(), | ||
nullable=False, | ||
existing_server_default=sa.text('now()')) | ||
batch_op.alter_column('submitted_payload', | ||
existing_type=postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=False) | ||
batch_op.alter_column('submitter_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=False) | ||
batch_op.drop_column('payload') | ||
|
||
with op.batch_alter_table('submission_history', schema=None) as batch_op: | ||
batch_op.alter_column('type', | ||
existing_type=postgresql.ENUM('other', 'standard', name='submissiontype'), | ||
nullable=False, | ||
autoincrement=False) | ||
batch_op.alter_column('submitted_datetime', | ||
existing_type=postgresql.TIMESTAMP(timezone=True), | ||
type_=sa.DateTime(), | ||
nullable=False, | ||
autoincrement=False) | ||
batch_op.alter_column('submitted_payload', | ||
existing_type=postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=False, | ||
autoincrement=False) | ||
batch_op.alter_column('submitter_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=False, | ||
autoincrement=False) | ||
batch_op.drop_column('payload') | ||
|
||
with op.batch_alter_table('users', schema=None) as batch_op: | ||
batch_op.alter_column('username', | ||
existing_type=sa.VARCHAR(length=1000), | ||
nullable=False) | ||
batch_op.alter_column('sub', | ||
existing_type=sa.VARCHAR(length=36), | ||
nullable=False) | ||
batch_op.alter_column('iss', | ||
existing_type=sa.VARCHAR(length=1024), | ||
nullable=False) | ||
batch_op.alter_column('idp_userid', | ||
existing_type=sa.VARCHAR(length=256), | ||
nullable=False) | ||
batch_op.alter_column('creation_date', | ||
existing_type=postgresql.TIMESTAMP(timezone=True), | ||
type_=sa.DateTime(), | ||
nullable=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('users', schema=None) as batch_op: | ||
batch_op.alter_column('creation_date', | ||
existing_type=sa.DateTime(), | ||
type_=postgresql.TIMESTAMP(timezone=True), | ||
nullable=True) | ||
batch_op.alter_column('idp_userid', | ||
existing_type=sa.VARCHAR(length=256), | ||
nullable=True) | ||
batch_op.alter_column('iss', | ||
existing_type=sa.VARCHAR(length=1024), | ||
nullable=True) | ||
batch_op.alter_column('sub', | ||
existing_type=sa.VARCHAR(length=36), | ||
nullable=True) | ||
batch_op.alter_column('username', | ||
existing_type=sa.VARCHAR(length=1000), | ||
nullable=True) | ||
|
||
with op.batch_alter_table('submission_history', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('payload', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True)) | ||
batch_op.alter_column('submitter_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=True, | ||
autoincrement=False) | ||
batch_op.alter_column('submitted_payload', | ||
existing_type=postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True, | ||
autoincrement=False) | ||
batch_op.alter_column('submitted_datetime', | ||
existing_type=sa.DateTime(), | ||
type_=postgresql.TIMESTAMP(timezone=True), | ||
nullable=True, | ||
autoincrement=False) | ||
batch_op.alter_column('type', | ||
existing_type=postgresql.ENUM('other', 'standard', name='submissiontype'), | ||
nullable=True, | ||
autoincrement=False) | ||
|
||
with op.batch_alter_table('submission', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('payload', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True)) | ||
batch_op.alter_column('submitter_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=True) | ||
batch_op.alter_column('submitted_payload', | ||
existing_type=postgresql.JSONB(astext_type=sa.Text()), | ||
nullable=True) | ||
batch_op.alter_column('submitted_datetime', | ||
existing_type=sa.DateTime(), | ||
type_=postgresql.TIMESTAMP(timezone=True), | ||
nullable=True, | ||
existing_server_default=sa.text('now()')) | ||
batch_op.alter_column('type', | ||
existing_type=postgresql.ENUM('other', 'standard', name='submissiontype'), | ||
nullable=True) | ||
|
||
op.drop_table('ownership_history') | ||
op.drop_table('ownership') | ||
op.drop_table('person_history') | ||
op.drop_table('person') | ||
# ### end Alembic commands ### |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright © 2024 Province of British Columbia | ||
# | ||
# Licensed under the BSD 3 Clause License, (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# The template for the license can be found here | ||
# https://opensource.org/license/bsd-3-clause/ | ||
# | ||
# Redistribution and use in source and binary forms, | ||
# with or without modification, are permitted provided that the | ||
# following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
"""Base Model.""" | ||
|
||
from .db import db | ||
|
||
|
||
class Base(db.Model): | ||
"""Base model class for db tables.""" | ||
|
||
__abstract__ = True | ||
|
||
def save(self): | ||
"""Save and commit to the session.""" | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def save_to_session(self): | ||
"""Save to the session. Does not commit.""" | ||
db.session.add(self) | ||
|
||
return self | ||
|
||
@staticmethod | ||
def commit(): | ||
"""Commit the session.""" | ||
db.session.commit() | ||
|
||
@staticmethod | ||
def rollback(): | ||
"""RollBack the session.""" | ||
db.session.rollback() |
Oops, something went wrong.