forked from bcgov/lear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
19263 continuation in validation and db updates (bcgov#2720)
- Loading branch information
1 parent
77636c4
commit acdc05c
Showing
20 changed files
with
1,296 additions
and
115 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
legal-api/migrations/versions/c4732cd8abfd_jurisdiction.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,97 @@ | ||
"""jurisdiction | ||
Revision ID: c4732cd8abfd | ||
Revises: ef8f033d317b | ||
Create Date: 2024-05-24 14:38:45.440604 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'c4732cd8abfd' | ||
down_revision = 'ef8f033d317b' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table('jurisdictions', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('country', sa.String(length=10), nullable=False), | ||
sa.Column('region', sa.String(length=10), nullable=True), | ||
sa.Column('identifier', sa.String(length=50), nullable=True), | ||
sa.Column('legal_name', sa.String(length=1000), nullable=True), | ||
sa.Column('tax_id', sa.String(length=15), nullable=True), | ||
sa.Column('incorporation_date', sa.DateTime(timezone=True), nullable=True), | ||
sa.Column('expro_identifier', sa.String(length=10), nullable=True), | ||
sa.Column('expro_legal_name', sa.String(length=1000), nullable=True), | ||
sa.Column('business_id', sa.Integer(), nullable=False), | ||
sa.Column('filing_id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['business_id'], ['businesses.id'], ), | ||
sa.ForeignKeyConstraint(['filing_id'], ['filings.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_jurisdictions_business_id'), 'jurisdictions', ['business_id'], unique=False) | ||
op.create_index(op.f('ix_jurisdictions_filing_id'), 'jurisdictions', ['filing_id'], unique=False) | ||
|
||
op.create_table('jurisdictions_version', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('country', sa.String(length=10), nullable=False), | ||
sa.Column('region', sa.String(length=10), nullable=True), | ||
sa.Column('identifier', sa.String(length=50), nullable=True), | ||
sa.Column('legal_name', sa.String(length=1000), nullable=True), | ||
sa.Column('tax_id', sa.String(length=15), nullable=True), | ||
sa.Column('incorporation_date', sa.DateTime(timezone=True), nullable=True), | ||
sa.Column('expro_identifier', sa.String(length=10), nullable=True), | ||
sa.Column('expro_legal_name', sa.String(length=1000), nullable=True), | ||
sa.Column('business_id', sa.Integer(), nullable=False), | ||
sa.Column('filing_id', sa.Integer(), nullable=False), | ||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False), | ||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True), | ||
sa.Column('operation_type', sa.SmallInteger(), nullable=False), | ||
sa.ForeignKeyConstraint(['filing_id'], ['filings.id']), | ||
sa.ForeignKeyConstraint(['business_id'], ['businesses.id']), | ||
sa.PrimaryKeyConstraint('id', 'transaction_id') | ||
) | ||
op.create_index(op.f('ix_jurisdictions_version_end_transaction_id'), 'jurisdictions_version', ['end_transaction_id'], unique=False) | ||
op.create_index(op.f('ix_jurisdictions_version_business_id'), 'jurisdictions_version', ['business_id'], unique=False) | ||
op.create_index(op.f('ix_jurisdictions_version_filing_id'), 'jurisdictions_version', ['filing_id'], unique=False) | ||
op.create_index(op.f('ix_jurisdictions_version_operation_type'), 'jurisdictions_version', ['operation_type'], unique=False) | ||
op.create_index(op.f('ix_jurisdictions_version_transaction_id'), 'jurisdictions_version', ['transaction_id'], unique=False) | ||
|
||
op.drop_column('businesses', 'foreign_legal_type') | ||
op.drop_column('businesses', 'foreign_identifier') | ||
op.drop_column('businesses', 'foreign_incorporation_date') | ||
|
||
op.drop_column('businesses_version', 'foreign_legal_type') | ||
op.drop_column('businesses_version', 'foreign_identifier') | ||
op.drop_column('businesses_version', 'foreign_incorporation_date') | ||
|
||
op.add_column('documents', sa.Column('file_name', sa.String(length=1000), nullable=True)) | ||
op.add_column('documents_version', sa.Column('file_name', sa.String(length=1000), nullable=True)) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('documents_version', 'file_name') | ||
op.drop_column('documents', 'file_name') | ||
|
||
op.add_column('businesses_version', sa.Column('foreign_incorporation_date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True)) | ||
op.add_column('businesses_version', sa.Column('foreign_identifier', sa.VARCHAR(length=15), autoincrement=False, nullable=True)) | ||
op.add_column('businesses_version', sa.Column('foreign_legal_type', sa.VARCHAR(length=10), autoincrement=False, nullable=True)) | ||
|
||
op.add_column('businesses', sa.Column('foreign_incorporation_date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True)) | ||
op.add_column('businesses', sa.Column('foreign_identifier', sa.VARCHAR(length=15), autoincrement=False, nullable=True)) | ||
op.add_column('businesses', sa.Column('foreign_legal_type', sa.VARCHAR(length=10), autoincrement=False, nullable=True)) | ||
|
||
op.drop_index(op.f('ix_jurisdictions_version_end_transaction_id'), table_name='jurisdictions_version') | ||
op.drop_index(op.f('ix_jurisdictions_version_business_id'), table_name='jurisdictions_version') | ||
op.drop_index(op.f('ix_jurisdictions_version_filing_id'), table_name='jurisdictions_version') | ||
op.drop_index(op.f('ix_jurisdictions_version_operation_type'), table_name='jurisdictions_version') | ||
op.drop_index(op.f('ix_jurisdictions_version_transaction_id'), table_name='jurisdictions_version') | ||
op.drop_table('jurisdictions_version') | ||
|
||
op.drop_index(op.f('ix_jurisdictions_business_id'), table_name='jurisdictions') | ||
op.drop_index(op.f('ix_jurisdictions_filing_id'), table_name='jurisdictions') | ||
op.drop_table('jurisdictions') |
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 |
---|---|---|
|
@@ -61,4 +61,4 @@ minio==7.0.2 | |
PyPDF2==1.26.0 | ||
reportlab==3.6.12 | ||
html-sanitizer==2.4.1 | ||
git+https://github.com/bcgov/[email protected].25#egg=registry_schemas | ||
git+https://github.com/bcgov/[email protected].27#egg=registry_schemas |
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 |
---|---|---|
@@ -1 +1 @@ | ||
git+https://github.com/bcgov/[email protected].25#egg=registry_schemas | ||
git+https://github.com/bcgov/[email protected].27#egg=registry_schemas |
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
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,64 @@ | ||
# Copyright © 2024 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""This module holds the data about jurisdiction.""" | ||
from __future__ import annotations | ||
|
||
from .db import db | ||
from .filing import Filing | ||
|
||
|
||
class Jurisdiction(db.Model): # pylint: disable=too-many-instance-attributes | ||
"""This class manages the jurisdiction.""" | ||
|
||
__versioned__ = {} | ||
__tablename__ = 'jurisdictions' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
country = db.Column('country', db.String(10)) | ||
region = db.Column('region', db.String(10)) | ||
identifier = db.Column('identifier', db.String(50)) | ||
legal_name = db.Column('legal_name', db.String(1000)) | ||
tax_id = db.Column('tax_id', db.String(15)) | ||
incorporation_date = db.Column('incorporation_date', db.DateTime(timezone=True)) | ||
expro_identifier = db.Column('expro_identifier', db.String(10)) | ||
expro_legal_name = db.Column('expro_legal_name', db.String(1000)) | ||
|
||
# parent keys | ||
business_id = db.Column('business_id', db.Integer, db.ForeignKey('businesses.id'), nullable=False, index=True) | ||
filing_id = db.Column('filing_id', db.Integer, db.ForeignKey('filings.id'), nullable=False, index=True) | ||
|
||
def save(self): | ||
"""Save the object to the database immediately.""" | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
@classmethod | ||
def find_by_id(cls, jurisdiction_id) -> Jurisdiction: | ||
"""Return jurisdiction by the id.""" | ||
jurisdiction = None | ||
if jurisdiction_id: | ||
jurisdiction = cls.query.filter_by(id=jurisdiction_id).one_or_none() | ||
return jurisdiction | ||
|
||
@classmethod | ||
def get_continuation_in_jurisdiction(cls, business_id) -> Jurisdiction: | ||
"""Return continuation in jurisdiction by the business id.""" | ||
jurisdiction = None | ||
if business_id: | ||
# pylint: disable=protected-access | ||
jurisdiction = (db.session.query(Jurisdiction).join(Filing). | ||
filter(Jurisdiction.business_id == business_id). | ||
filter(Filing._filing_type == 'continuationIn'). | ||
one_or_none()) | ||
return jurisdiction |
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
Oops, something went wrong.