add new key_type table

* single-column static data table that currently contains two types: 'normal' and 'team'
* key_type foreign-keyed from api_keys
  - must be not null
  - existing rows set to 'normal'
* key_type foreign-keyed from notifications
  - nullable
  - existing rows set to null
* api_key foreign-keyed from notifications
  - nullable
  - existing rows set to null
This commit is contained in:
Leo Hemsted
2016-06-23 16:45:20 +01:00
parent f371c393a2
commit e9482c7fe1
10 changed files with 123 additions and 25 deletions

View File

@@ -113,6 +113,7 @@ class ApiKey(db.Model, Versioned):
secret = db.Column(db.String(255), unique=True, nullable=False)
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False)
service = db.relationship('Service', backref=db.backref('api_keys', lazy='dynamic'))
key_type = db.Column(db.String(255), db.ForeignKey('key_types.name'), index=True, nullable=False)
expiry_date = db.Column(db.DateTime)
created_at = db.Column(
db.DateTime,
@@ -134,6 +135,16 @@ class ApiKey(db.Model, Versioned):
)
KEY_TYPE_NORMAL = 'normal'
KEY_TYPE_TEAM = 'team'
class KeyTypes(db.Model):
__tablename__ = 'key_types'
name = db.Column(db.String(255), primary_key=True)
class NotificationStatistics(db.Model):
__tablename__ = 'notification_statistics'
@@ -329,6 +340,9 @@ class Notification(db.Model):
template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, unique=False)
template = db.relationship('Template')
template_version = db.Column(db.Integer, nullable=False)
api_key_id = db.Column(UUID(as_uuid=True), db.ForeignKey('api_keys.id'), index=True, unique=False)
api_key = db.relationship('ApiKey')
key_type = db.Column(db.String, db.ForeignKey('key_types.name'), index=True, unique=False)
content_char_count = db.Column(db.Integer, nullable=True)
created_at = db.Column(
db.DateTime,