Skip to content

Commit

Permalink
22827 - add sql-versioning library & versioning switching logic
Browse files Browse the repository at this point in the history
Signed-off-by: chenhongjing <60866283+chenhongjing@users.noreply.github.com>
  • Loading branch information
chenhongjing committed Oct 10, 2024
1 parent afa6492 commit e4d0418
Show file tree
Hide file tree
Showing 38 changed files with 1,618 additions and 49 deletions.
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
}
}
}
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
4 changes: 3 additions & 1 deletion legal-api/src/legal_api/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"""
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
4 changes: 3 additions & 1 deletion legal-api/src/legal_api/models/amalgamating_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
from sqlalchemy import or_
from sqlalchemy_continuum import version_class

from sql_versioning import Versioned

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
4 changes: 3 additions & 1 deletion legal-api/src/legal_api/models/amalgamation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
from sqlalchemy import or_
from sqlalchemy_continuum import version_class

from sql_versioning import Versioned

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 @@ -32,6 +32,7 @@
from legal_api.utils.base import BaseEnum
from legal_api.utils.datetime import datetime, timezone
from legal_api.utils.legislation_datetime import LegislationDatetime
from sql_versioning import Versioned

from .amalgamation import Amalgamation # noqa: F401, I001, I003 pylint: disable=unused-import
from .batch import Batch # noqa: F401, I001, I003 pylint: disable=unused-import
Expand All @@ -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__ = {}
__tablename__ = 'corp_types'

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

0 comments on commit e4d0418

Please sign in to comment.