-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2024 from Pylons/feature/alchemy-scaffold-update
alchemy scaffold updates
- Loading branch information
Showing
200 changed files
with
5,142 additions
and
3,497 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
from sqlalchemy.orm import configure_mappers | ||
# import all models classes here for sqlalchemy mappers | ||
# to pick up | ||
from .mymodel import MyModel # flake8: noqa | ||
|
||
# run configure mappers to ensure we avoid any race conditions | ||
configure_mappers() |
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,49 @@ | ||
from sqlalchemy import engine_from_config | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
from sqlalchemy.schema import MetaData | ||
import zope.sqlalchemy | ||
|
||
# Recommended naming convention used by Alembic, as various different database | ||
# providers will autogenerate vastly different names making migrations more | ||
# difficult. See: http://alembic.readthedocs.org/en/latest/naming.html | ||
NAMING_CONVENTION = { | ||
"ix": 'ix_%(column_0_label)s', | ||
"uq": "uq_%(table_name)s_%(column_0_name)s", | ||
"ck": "ck_%(table_name)s_%(constraint_name)s", | ||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | ||
"pk": "pk_%(table_name)s" | ||
} | ||
|
||
metadata = MetaData(naming_convention=NAMING_CONVENTION) | ||
Base = declarative_base(metadata=metadata) | ||
|
||
|
||
def includeme(config): | ||
settings = config.get_settings() | ||
dbmaker = get_dbmaker(get_engine(settings)) | ||
|
||
config.add_request_method( | ||
lambda r: get_session(r.tm, dbmaker), | ||
'dbsession', | ||
reify=True | ||
) | ||
|
||
config.include('pyramid_tm') | ||
|
||
|
||
def get_session(transaction_manager, dbmaker): | ||
dbsession = dbmaker() | ||
zope.sqlalchemy.register(dbsession, | ||
transaction_manager=transaction_manager) | ||
return dbsession | ||
|
||
|
||
def get_engine(settings, prefix='sqlalchemy.'): | ||
return engine_from_config(settings, prefix) | ||
|
||
|
||
def get_dbmaker(engine): | ||
dbmaker = sessionmaker() | ||
dbmaker.configure(bind=engine) | ||
return dbmaker |
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,19 @@ | ||
from .meta import Base | ||
from sqlalchemy import ( | ||
Column, | ||
Index, | ||
Integer, | ||
Text, | ||
) | ||
|
||
|
||
# Start Sphinx Include | ||
class MyModel(Base): | ||
__tablename__ = 'models' | ||
id = Column(Integer, primary_key=True) | ||
name = Column(Text) | ||
value = Column(Integer) | ||
# End Sphinx Include | ||
|
||
|
||
Index('my_index', MyModel.name, unique=True, mysql_length=255) |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.