Initial content as generated from scaffold

This commit is contained in:
Lance Edgar 2019-08-16 20:46:01 +00:00
commit 9b0bbb74c2
27 changed files with 748 additions and 0 deletions

View file

View file

@ -0,0 +1 @@
Generic single-database configuration.

View file

@ -0,0 +1,76 @@
# -*- coding: utf-8; mode: python; -*-
"""
Alembic environment script
"""
from __future__ import unicode_literals, absolute_import
from alembic import context
from sqlalchemy.orm import configure_mappers
from rattail.config import make_config
from rattail.db.util import get_default_engine
from rattail.db.continuum import configure_versioning
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
alembic_config = context.config
# use same config file for Rattail
rattail_config = make_config(alembic_config.config_file_name, usedb=False, versioning=False)
# configure Continuum..this is trickier than we want but it works..
configure_versioning(rattail_config, force=True)
from rattail_tutorial.db import model
configure_mappers()
# needed for 'autogenerate' support
target_metadata = model.Base.metadata
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
engine = get_default_engine(rattail_config)
context.configure(
url=engine.url,
target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = get_default_engine(rattail_config)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8; mode: python; -*-
# -*- coding: utf-8 -*-
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from __future__ import unicode_literals, absolute_import
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
from alembic import op
import sqlalchemy as sa
import rattail.db.types
${imports if imports else ""}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View file

@ -0,0 +1,12 @@
# -*- coding: utf-8; mode: python; -*-
"""
Rattail Tutorial data models
"""
from __future__ import unicode_literals, absolute_import
# bring in all the normal stuff from Rattail
from rattail.db.model import *
# add Rattail Tutorial models
from .core import Rattail_tutorialCustomer

View file

@ -0,0 +1,43 @@
# -*- coding: utf-8; mode: python -*-
"""
Rattail core data model extensions
"""
from __future__ import unicode_literals, absolute_import
import sqlalchemy as sa
from sqlalchemy import orm
from rattail.db import model
from rattail.db.core import uuid_column
class Rattail_tutorialCustomer(model.Base):
"""
Rattail Tutorial extensions to core Customer model
"""
__tablename__ = 'rattail_tutorial_customer'
__table_args__ = (
sa.ForeignKeyConstraint(['uuid'], ['customer.uuid'], name='rattail_tutorial_customer_fk_customer'),
)
uuid = uuid_column(default=None)
customer = orm.relationship(
model.Customer,
doc="""
Customer to which this extension record pertains.
""",
backref=orm.backref(
'_rattail_tutorial',
uselist=False,
cascade='all, delete-orphan',
doc="""
Rattail Tutorial-specific extension record for the customer.
"""),
)
mail_list_synced = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
Flag indicating whether the customer's email address has been synced to the
general mailing list.
""")