1
0
Fork 0

Change referal key from uuid to urlsafe token via secrets module

Also, added compare_type=True to migration env
to catch changes like this in the future

Other than that the title says it all buddy boi
This commit is contained in:
Derek Schmidt 2018-05-31 15:48:58 -07:00
parent e90f6fb215
commit c7a9639a29
Signed by: skeh
GPG key ID: 0F5D491793B4035A
3 changed files with 39 additions and 4 deletions

View file

@ -41,7 +41,7 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)
context.configure(url=url, compare_type=True)
with context.begin_transaction():
context.run_migrations()
@ -73,6 +73,7 @@ def run_migrations_online():
context.configure(connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
compare_type=True,
**current_app.extensions['migrate'].configure_args)
try:

View file

@ -0,0 +1,34 @@
"""empty message
Revision ID: ea5307f715d1
Revises: bb298ef84235
Create Date: 2018-05-31 15:47:34.645982
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'ea5307f715d1'
down_revision = 'bb298ef84235'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('referal', 'key',
existing_type=sa.String(length=36),
type_=sa.String(length=43),
existing_nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('referal', 'key',
existing_type=sa.String(length=43),
type_=sa.String(length=36),
existing_nullable=True)
# ### end Alembic commands ###

View file

@ -1,7 +1,7 @@
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
import bcrypt
import uuid
import secrets
db = SQLAlchemy()
@ -38,14 +38,14 @@ class User(db.Model, UserMixin):
class Referal(db.Model):
id = db.Column(db.Integer, primary_key=True)
key = db.Column(db.String(36), index=True)
key = db.Column(db.String(43), index=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
message = db.Column(db.String(), nullable=True)
kwargs = db.Column(db.PickleType, nullable=True)
def __init__(self, user, message=None, **kwargs):
self.user_id = user.id
self.key = str(uuid.uuid4())
self.key = secrets.token_urlsafe()
self.message = message
self.args = kwargs