diff --git a/alembic/env.py b/alembic/env.py index 20a9163..c95032c 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -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") diff --git a/instance/settings-sample.py b/instance/settings-sample.py index bde7ebf..a2b3b5e 100644 --- a/instance/settings-sample.py +++ b/instance/settings-sample.py @@ -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' diff --git a/instance/testing.py b/instance/testing.py index 6dc4338..24a6b7a 100644 --- a/instance/testing.py +++ b/instance/testing.py @@ -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' diff --git a/lastuser_core/models/client.py b/lastuser_core/models/client.py index 1eaeb9c..0b633bd 100644 --- a/lastuser_core/models/client.py +++ b/lastuser_core/models/client.py @@ -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) @@ -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', @@ -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')) @@ -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) @@ -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, @@ -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) @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/lastuser_core/models/notification.py b/lastuser_core/models/notification.py index 1f31cce..aa9ea88 100644 --- a/lastuser_core/models/notification.py +++ b/lastuser_core/models/notification.py @@ -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) @@ -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) @@ -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) diff --git a/lastuser_core/models/session.py b/lastuser_core/models/session.py index f4db4f0..8724c68 100644 --- a/lastuser_core/models/session.py +++ b/lastuser_core/models/session.py @@ -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') diff --git a/lastuser_core/models/user.py b/lastuser_core/models/user.py index 18cce78..859ba67 100644 --- a/lastuser_core/models/user.py +++ b/lastuser_core/models/user.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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')) @@ -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')) @@ -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')) @@ -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')) @@ -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) @@ -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,