Define custom data model; add alembic scripts; etc.

actually our "custom" data model is just rattail + rattail-corepos
This commit is contained in:
Lance Edgar 2020-03-04 19:08:20 -06:00
parent f4a1868aaf
commit 72a4c347d8
7 changed files with 133 additions and 4 deletions

View file

@ -1,10 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8; -*-
""" """
Rattail Demo config extension Rattail Demo config extension
""" """
from __future__ import unicode_literals, absolute_import
from rattail.config import ConfigExtension from rattail.config import ConfigExtension
@ -17,5 +15,6 @@ class DemoConfigExtension(ConfigExtension):
def configure(self, config): def configure(self, config):
# tell rattail where our stuff lives # tell rattail where our stuff lives
config.setdefault('rattail', 'model', 'rattail_demo.db.model')
config.setdefault('rattail.mail', 'emails', 'rattail_demo.emails') config.setdefault('rattail.mail', 'emails', 'rattail_demo.emails')
config.setdefault('tailbone', 'menus', 'rattail_demo.web.menus') config.setdefault('tailbone', 'menus', 'rattail_demo.web.menus')

View file

View file

@ -0,0 +1,74 @@
# -*- coding: utf-8; mode: python; -*-
"""
Alembic environment script
"""
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_demo.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,28 @@
# -*- coding: utf-8; mode: python; -*-
# -*- coding: utf-8 -*-
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
# 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"}

10
rattail_demo/db/model.py Normal file
View file

@ -0,0 +1,10 @@
# -*- coding: utf-8; -*-
"""
Rattail Demo data model
"""
# bring in all the normal stuff from Rattail
from rattail.db.model import *
# also bring in CORE integration models
from rattail_corepos.db.model import *

View file

@ -34,7 +34,7 @@ def includeme(config):
config.include('rattail_demo.web.views.tempmon') config.include('rattail_demo.web.views.tempmon')
config.include('rattail_demo.web.views.upgrades') config.include('rattail_demo.web.views.upgrades')
config.include('rattail_demo.web.views.users') config.include('rattail_demo.web.views.users')
config.include('tailbone.views.vendors') config.include('rattail_demo.web.views.vendors')
# core-pos views # core-pos views
config.include('tailbone_corepos.views.corepos') config.include('tailbone_corepos.views.corepos')

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8; -*-
"""
Vendor views
"""
from tailbone.views import vendors as base
# NOTE: the main point of this module is to bring this in
from tailbone_corepos.views.vendors import VendorView
def includeme(config):
# autocomplete
config.add_route('vendors.autocomplete', '/vendors/autocomplete')
config.add_view(base.VendorsAutocomplete, route_name='vendors.autocomplete',
renderer='json', permission='vendors.list')
VendorView.defaults(config)