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

22827 - Add sql-versioning library and versioning switching logic #3024

Merged
merged 13 commits into from
Oct 21, 2024
1 change: 1 addition & 0 deletions jobs/furnishings/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ requests==2.25.1
cachelib==0.9.0
git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api
git+https://github.com/bcgov/[email protected]#egg=registry_schemas
git+https://github.com/bcgov/lear.git#egg=sql-versioning&subdirectory=python/common/sql-versioning
3 changes: 2 additions & 1 deletion jobs/furnishings/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

from datedelta import datedelta
from freezegun import freeze_time

from legal_api.models import Address, Batch, BatchProcessing, Business, Filing, Furnishing, db
from legal_api.models.colin_event_id import ColinEventId
from sqlalchemy_continuum import versioning_manager
from legal_api.models.db import versioning_manager


EPOCH_DATETIME = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc)
Expand Down
13 changes: 13 additions & 0 deletions legal-api/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
"involuntary-dissolution-filter": {
"include-accounts": [],
"exclude-accounts": []
},
"db-versioning": {
"legal-api": false,
"emailer": false,
"filer": false,
"entity-bn": false,
"digital-credentials": false,
"dissolutions-job": false,
"furnishings-job": false,
"emailer-reminder-job": false,
"future-effective-job": false,
"update-colin-filings-job": false,
"update-legal-filings-job": false
}
Comment on lines +13 to 25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have this flag setup for each environment in LD already?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, and the related setup_versioning() function is commented out so there's no impact. But I'll set them up now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The flag is off for all env.

Current on value:

 {
    "legal-api": false,
    "emailer": false,
    "filer": false,
    "entity-bn": false,
    "digital-credentials": false,
    "dissolutions-job": false,
    "furnishings-job": false,
    "emailer-reminder-job": false,
    "future-effective-job": false,
    "update-colin-filings-job": false,
    "update-legal-filings-job": false
}

Current off value:

{}

}
}
1 change: 1 addition & 0 deletions legal-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ reportlab==3.6.12
html-sanitizer==2.4.1
lxml==5.2.2
git+https://github.com/bcgov/[email protected]#egg=registry_schemas
git+https://github.com/bcgov/lear.git#egg=sql-versioning&subdirectory=python/common/sql-versioning
3 changes: 2 additions & 1 deletion legal-api/src/legal_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from legal_api import config, models
from legal_api.models import db
from legal_api.models.db import init_db
from legal_api.resources import endpoints
from legal_api.schemas import rsbc_schemas
from legal_api.services import digital_credentials, flags, queue
Expand Down Expand Up @@ -54,7 +55,7 @@ def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
send_default_pii=False
)

db.init_app(app)
init_db(app)
rsbc_schemas.init_app(app)
flags.init_app(app)
queue.init_app(app)
Expand Down
1 change: 1 addition & 0 deletions legal-api/src/legal_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class _Config(): # pylint: disable=too-few-public-methods
Used as the base for all the other configurations.
"""

SERVICE_NAME = 'legal-api'
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

LEGAL_API_BASE_URL = os.getenv('LEGAL_API_BASE_URL', 'https://LEGAL_API_BASE_URL/api/v1/businesses')
Expand Down
3 changes: 2 additions & 1 deletion legal-api/src/legal_api/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
Currently this only provides API versioning information
"""
import pycountry
from sql_versioning import Versioned

from .db import db


class Address(db.Model): # pylint: disable=too-many-instance-attributes
class Address(db.Model, Versioned): # pylint: disable=too-many-instance-attributes
"""This class manages all of the business addresses.

Every business is required to have 2 addresses on record, DELIVERY and MAILING.
Expand Down
4 changes: 3 additions & 1 deletion legal-api/src/legal_api/models/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

from enum import Enum

from sql_versioning import Versioned

from .db import db


class Alias(db.Model): # pylint: disable=too-many-instance-attributes
class Alias(db.Model, Versioned): # pylint: disable=too-many-instance-attributes
"""This class manages the aliases."""

class AliasType(Enum):
Expand Down
3 changes: 2 additions & 1 deletion legal-api/src/legal_api/models/amalgamating_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

from enum import auto

from sql_versioning import Versioned
from sqlalchemy import or_
from sqlalchemy_continuum import version_class

from ..utils.base import BaseEnum
from .db import db


class AmalgamatingBusiness(db.Model): # pylint: disable=too-many-instance-attributes
class AmalgamatingBusiness(db.Model, Versioned): # pylint: disable=too-many-instance-attributes
"""This class manages the amalgamating businesses."""

# pylint: disable=invalid-name
Expand Down
3 changes: 2 additions & 1 deletion legal-api/src/legal_api/models/amalgamation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

from enum import auto

from sql_versioning import Versioned
from sqlalchemy import or_
from sqlalchemy_continuum import version_class

from ..utils.base import BaseEnum
from .db import db


class Amalgamation(db.Model): # pylint: disable=too-many-instance-attributes
class Amalgamation(db.Model, Versioned): # pylint: disable=too-many-instance-attributes
"""This class manages the amalgamations."""

# pylint: disable=invalid-name
Expand Down
3 changes: 2 additions & 1 deletion legal-api/src/legal_api/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import datedelta
import pytz
from flask import current_app
from sql_versioning import Versioned
from sqlalchemy.exc import OperationalError, ResourceClosedError
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import aliased, backref
Expand Down Expand Up @@ -50,7 +51,7 @@
from .user import User # noqa: F401,I003 pylint: disable=unused-import; needed by the SQLAlchemy backref


class Business(db.Model): # pylint: disable=too-many-instance-attributes,disable=too-many-public-methods
class Business(db.Model, Versioned): # pylint: disable=too-many-instance-attributes,disable=too-many-public-methods
"""This class manages all of the base data about a business.

A business is base form of any entity that can interact directly
Expand Down
1 change: 0 additions & 1 deletion legal-api/src/legal_api/models/corp_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
class CorpType(db.Model): # pylint: disable=too-many-instance-attributes
"""This class manages the corp type."""

__versioned__ = {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does corp_type have version table? I don't find it so I remove its old versioning.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't find it in DEV db on my side
image

__tablename__ = 'corp_types'

corp_type_cd = db.Column('corp_type_cd', db.String(5), primary_key=True)
Expand Down
Loading
Loading