Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Drop support for SQLAlchemy binds. It was never used anyway.
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed May 3, 2017
1 parent 4eef483 commit 0788787
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 37 deletions.
2 changes: 1 addition & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from flask import current_app
with current_app.app_context():
# set the database url
config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_BINDS', {}).get('lastuser', None))
config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI'))
flask_app = __import__('%s' % (current_app.name), fromlist=[current_app.name])

db_obj_name = config.get_main_option("flask_sqlalchemy")
Expand Down
4 changes: 1 addition & 3 deletions instance/settings-sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
GA_CODE = ''

#: Database backend
SQLALCHEMY_BINDS = {
'lastuser': 'sqlite:///test.db',
}
SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db'

#: Cache type
CACHE_TYPE = 'redis'
Expand Down
4 changes: 1 addition & 3 deletions instance/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
DEBUG_TB_INTERCEPT_REDIRECTS = False
SERVER_NAME='test.lastuser.dev:7500'
LOGFILE = 'error.log'
SQLALCHEMY_BINDS = {
'lastuser': environ.get('SQLALCHEMY_DATABASE_URI', 'postgres://@localhost:5432/lastuser_test_app'),
}
SQLALCHEMY_DATABASE_URI = environ.get('SQLALCHEMY_DATABASE_URI', 'postgres://@localhost:5432/lastuser_test_app')
SQLALCHEMY_ECHO = False
SECRET_KEY = 'random_string_here'
TIMEZONE = 'Asia/Calcutta'
Expand Down
12 changes: 0 additions & 12 deletions lastuser_core/models/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def add_scope(self, additional):
class Client(ScopeMixin, BaseMixin, db.Model):
"""OAuth client applications"""
__tablename__ = 'client'
__bind_key__ = 'lastuser'
__scope_null_allowed__ = True
#: User who owns this client
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
Expand Down Expand Up @@ -179,7 +178,6 @@ class ClientCredential(BaseMixin, db.Model):
prefixed with 'sha256$'.
"""
__tablename__ = 'client_credential'
__bind_key__ = 'lastuser'
client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable=False)
client = db.relationship(Client, primaryjoin=client_id == Client.id,
backref=db.backref('credentials', cascade='all, delete-orphan',
Expand Down Expand Up @@ -221,7 +219,6 @@ class UserFlashMessage(BaseMixin, db.Model):
Saved messages for a user, to be relayed to trusted clients.
"""
__tablename__ = 'userflashmessage'
__bind_key__ = 'lastuser'
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
user = db.relationship(User, primaryjoin=user_id == User.id,
backref=db.backref('flashmessages', cascade='delete, delete-orphan'))
Expand All @@ -237,7 +234,6 @@ class Resource(BaseScopedNameMixin, db.Model):
`name` as part of the requested `scope`.
"""
__tablename__ = 'resource'
__bind_key__ = 'lastuser'
# Resource names are unique within client apps
name = db.Column(db.Unicode(20), nullable=False)
client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable=False)
Expand Down Expand Up @@ -287,7 +283,6 @@ class ResourceAction(BaseMixin, db.Model):
Actions that can be performed on resources.
"""
__tablename__ = 'resourceaction'
__bind_key__ = 'lastuser'
name = db.Column(db.Unicode(20), nullable=False)
resource_id = db.Column(db.Integer, db.ForeignKey('resource.id'), nullable=False)
resource = db.relationship(Resource, primaryjoin=resource_id == Resource.id,
Expand Down Expand Up @@ -319,7 +314,6 @@ def get(cls, name, resource):
class AuthCode(ScopeMixin, BaseMixin, db.Model):
"""Short-lived authorization tokens"""
__tablename__ = 'authcode'
__bind_key__ = 'lastuser'
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
user = db.relationship(User, primaryjoin=user_id == User.id)
client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable=False)
Expand All @@ -340,7 +334,6 @@ def is_valid(self):
class AuthToken(ScopeMixin, BaseMixin, db.Model):
"""Access tokens for access to data"""
__tablename__ = 'authtoken'
__bind_key__ = 'lastuser'
# Null for client-only tokens and public clients (user is identified via user_session.user there)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
_user = db.relationship(User, primaryjoin=user_id == User.id,
Expand Down Expand Up @@ -482,7 +475,6 @@ def all(cls, users):

class Permission(BaseMixin, db.Model):
__tablename__ = 'permission'
__bind_key__ = 'lastuser'
#: User who created this permission
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
user = db.relationship(User, primaryjoin=user_id == User.id,
Expand Down Expand Up @@ -545,7 +537,6 @@ def get(cls, name, user=None, org=None, allusers=False):
# This model's name is in plural because it defines multiple permissions within each instance
class UserClientPermissions(BaseMixin, db.Model):
__tablename__ = 'userclientpermissions'
__bind_key__ = 'lastuser'
#: User who has these permissions
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
user = db.relationship(User, primaryjoin=user_id == User.id,
Expand Down Expand Up @@ -591,7 +582,6 @@ def migrate_user(cls, olduser, newuser):
# This model's name is in plural because it defines multiple permissions within each instance
class TeamClientPermissions(BaseMixin, db.Model):
__tablename__ = 'teamclientpermissions'
__bind_key__ = 'lastuser'
#: Team which has these permissions
team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False)
team = db.relationship(Team, primaryjoin=team_id == Team.id,
Expand Down Expand Up @@ -625,7 +615,6 @@ class CLIENT_TEAM_ACCESS:

class ClientTeamAccess(BaseMixin, db.Model):
__tablename__ = 'clientteamaccess'
__bind_key__ = 'lastuser'
#: Organization whose teams are exposed to the client app
org_id = db.Column(db.Integer, db.ForeignKey('organization.id'), nullable=True)
org = db.relationship(Organization, primaryjoin=org_id == Organization.id,
Expand All @@ -639,7 +628,6 @@ class ClientTeamAccess(BaseMixin, db.Model):

class NoticeType(BaseMixin, db.Model):
__tablename__ = 'noticetype'
__bind_key__ = 'lastuser'
#: User who created this notice type
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
user = db.relationship(User, primaryjoin=user_id == User.id,
Expand Down
3 changes: 0 additions & 3 deletions lastuser_core/models/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class ChannelSMS(Channel):

class SMSMessage(BaseMixin, db.Model):
__tablename__ = 'smsmessage'
__bind_key__ = 'lastuser'
# Phone number that the message was sent to
phone_number = db.Column(db.String(15), nullable=False)
transaction_id = db.Column(db.Unicode(40), unique=True, nullable=True)
Expand Down Expand Up @@ -146,7 +145,6 @@ class SMSMessage(BaseMixin, db.Model):
# """

# __tablename__ = 'notification_class'
# __bind_key__ = 'lastuser'

# #: Client app that will send these notifications
# client_id = db.Column(None, db.ForeignKey('client.id'), nullable=False)
Expand All @@ -169,7 +167,6 @@ class SMSMessage(BaseMixin, db.Model):

# class UserNotificationPreference(ChannelMixin, BaseMixin, db.Model):
# __tablename__ = 'user_notification_preference'
# __bind_key__ = 'lastuser'

# #: The notification class these preferences are for
# notification_class_id = db.Column(None, db.ForeignKey('notification_class.id'), nullable=False)
Expand Down
4 changes: 1 addition & 3 deletions lastuser_core/models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
'session_client', db.Model.metadata,
*(make_timestamp_columns() + (
db.Column('user_session_id', None, db.ForeignKey('user_session.id'), nullable=False, primary_key=True),
db.Column('client_id', None, db.ForeignKey('client.id'), nullable=False, primary_key=True))),
info={'bind_key': 'lastuser'}
db.Column('client_id', None, db.ForeignKey('client.id'), nullable=False, primary_key=True)))
)


class UserSession(BaseMixin, db.Model):
__tablename__ = 'user_session'
__bind_key__ = 'lastuser'

buid = db.Column(db.Unicode(22), nullable=False, unique=True, default=make_buid)
sessionid = db.synonym('buid')
Expand Down
13 changes: 1 addition & 12 deletions lastuser_core/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class USER_STATUS:

class User(BaseMixin, db.Model):
__tablename__ = 'user'
__bind_key__ = 'lastuser'
#: UUID that replaces userid going forward
uuid = db.Column(UUIDType(binary=False), default=uuid1mc, unique=True, nullable=False)
#: The userid, a globally unique and permanent string to identify this user
Expand Down Expand Up @@ -394,7 +393,6 @@ def autocomplete(cls, query):

class UserOldId(TimestampMixin, db.Model):
__tablename__ = 'useroldid'
__bind_key__ = 'lastuser'
query_class = CoasterQuery

# userid here is NOT a foreign key since it has to continue to exist
Expand Down Expand Up @@ -423,14 +421,12 @@ def get(cls, userid):
'team_membership', db.Model.metadata,
*(make_timestamp_columns() + (
db.Column('user_id', None, db.ForeignKey('user.id'), nullable=False, primary_key=True),
db.Column('team_id', None, db.ForeignKey('team.id'), nullable=False, primary_key=True))),
info={'bind_key': 'lastuser'}
db.Column('team_id', None, db.ForeignKey('team.id'), nullable=False, primary_key=True)))
)


class Organization(BaseMixin, db.Model):
__tablename__ = 'organization'
__bind_key__ = 'lastuser'
#: UUID that replaces userid going forward
uuid = db.Column(UUIDType(binary=False), default=uuid1mc, unique=True, nullable=False)
# owners_id cannot be null, but must be declared with nullable=True since there is
Expand Down Expand Up @@ -597,7 +593,6 @@ def all(cls, userids=None, names=None, defercols=False):

class Team(BaseMixin, db.Model):
__tablename__ = 'team'
__bind_key__ = 'lastuser'
#: UUID that replaces userid going forward
uuid = db.Column(UUIDType(binary=False), default=uuid1mc, unique=True, nullable=False)
#: Unique and non-changing id
Expand Down Expand Up @@ -685,7 +680,6 @@ def owner(self, value):

class UserEmail(OwnerMixin, BaseMixin, db.Model):
__tablename__ = 'useremail'
__bind_key__ = 'lastuser'
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=True)
user = db.relationship(User, primaryjoin=user_id == User.id,
backref=db.backref('emails', cascade='all, delete-orphan'))
Expand Down Expand Up @@ -762,7 +756,6 @@ def get(cls, email=None, md5sum=None):

class UserEmailClaim(OwnerMixin, BaseMixin, db.Model):
__tablename__ = 'useremailclaim'
__bind_key__ = 'lastuser'
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=True)
user = db.relationship(User, primaryjoin=user_id == User.id,
backref=db.backref('emailclaims', cascade='all, delete-orphan'))
Expand Down Expand Up @@ -847,7 +840,6 @@ def all(cls, email):

class UserPhone(OwnerMixin, BaseMixin, db.Model):
__tablename__ = 'userphone'
__bind_key__ = 'lastuser'
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=True)
user = db.relationship(User, primaryjoin=user_id == User.id,
backref=db.backref('phones', cascade='all, delete-orphan'))
Expand Down Expand Up @@ -905,7 +897,6 @@ def get(cls, phone):

class UserPhoneClaim(OwnerMixin, BaseMixin, db.Model):
__tablename__ = 'userphoneclaim'
__bind_key__ = 'lastuser'
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=True)
user = db.relationship(User, primaryjoin=user_id == User.id,
backref=db.backref('phoneclaims', cascade='all, delete-orphan'))
Expand Down Expand Up @@ -986,7 +977,6 @@ def all(cls, phone):

class PasswordResetRequest(BaseMixin, db.Model):
__tablename__ = 'passwordresetrequest'
__bind_key__ = 'lastuser'
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=False)
user = db.relationship(User, primaryjoin=user_id == User.id)
reset_code = db.Column(db.String(44), nullable=False, default=newsecret)
Expand All @@ -998,7 +988,6 @@ def __init__(self, **kwargs):

class UserExternalId(BaseMixin, db.Model):
__tablename__ = 'userexternalid'
__bind_key__ = 'lastuser'
__at_username_services__ = []
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=False)
user = db.relationship(User, primaryjoin=user_id == User.id,
Expand Down

0 comments on commit 0788787

Please sign in to comment.