https://github.com/CTFd/CTFd/milestone/6
This commit is contained in:
Kevin Chung
2019-04-17 01:36:30 -04:00
committed by GitHub
parent 33367422a5
commit b6d54b9ee9
278 changed files with 3659 additions and 13735 deletions

View File

@@ -0,0 +1,28 @@
"""Add type to awards
Revision ID: 4e4d5a9ea000
Revises: 8369118943a1
Create Date: 2019-04-07 19:37:17.872128
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '4e4d5a9ea000'
down_revision = '8369118943a1'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('awards', sa.Column('type', sa.String(length=80), nullable=True, server_default="standard"))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('awards', 'type')
# ### end Alembic commands ###

View File

@@ -1,7 +1,7 @@
"""Initial Revision
Revision ID: 8369118943a1
Revises:
Revises:
Create Date: 2018-11-05 01:06:24.495010
"""
@@ -22,43 +22,6 @@ branch_labels = None
depends_on = None
class SQLiteJson(TypeDecorator):
impl = String
class Comparator(String.Comparator):
def __getitem__(self, index):
if isinstance(index, tuple):
index = "$%s" % (
"".join([
"[%s]" % elem if isinstance(elem, int)
else '."%s"' % elem for elem in index
])
)
elif isinstance(index, int):
index = "$[%s]" % index
else:
index = '$."%s"' % index
# json_extract does not appear to return JSON sub-elements
# which is weird.
return func.json_extract(self.expr, index, type_=NullType)
comparator_factory = Comparator
def process_bind_param(self, value, dialect):
if value is not None:
value = json.dumps(value)
return value
def process_result_value(self, value, dialect):
if value is not None:
value = json.loads(value)
return value
JSON = types.JSON().with_variant(SQLiteJson, 'sqlite')
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('challenges',
@@ -70,7 +33,7 @@ def upgrade():
sa.Column('category', sa.String(length=80), nullable=True),
sa.Column('type', sa.String(length=80), nullable=True),
sa.Column('state', sa.String(length=80), nullable=False),
sa.Column('requirements', JSON, nullable=True),
sa.Column('requirements', sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('config',
@@ -142,7 +105,7 @@ def upgrade():
sa.Column('challenge_id', sa.Integer(), nullable=True),
sa.Column('content', sa.Text(), nullable=True),
sa.Column('cost', sa.Integer(), nullable=True),
sa.Column('requirements', JSON, nullable=True),
sa.Column('requirements', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['challenge_id'], ['challenges.id'], ),
sa.PrimaryKeyConstraint('id')
)
@@ -186,7 +149,7 @@ def upgrade():
sa.Column('value', sa.Integer(), nullable=True),
sa.Column('category', sa.String(length=80), nullable=True),
sa.Column('icon', sa.Text(), nullable=True),
sa.Column('requirements', JSON, nullable=True),
sa.Column('requirements', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')

View File

@@ -0,0 +1,55 @@
"""Add captain column to Teams
Revision ID: b5551cd26764
Revises: 4e4d5a9ea000
Create Date: 2019-04-12 00:29:08.021141
"""
from CTFd.models import db
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text, table, column, and_
# revision identifiers, used by Alembic.
revision = 'b5551cd26764'
down_revision = '4e4d5a9ea000'
branch_labels = None
depends_on = None
teams_table = table('teams',
column('id', db.Integer),
column('captain_id', db.Integer),
)
users_table = table('users',
column('id', db.Integer),
column('team_id', db.Integer),
)
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('teams', sa.Column('captain_id', sa.Integer(), nullable=True))
op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id'])
connection = op.get_bind()
for team in connection.execute(teams_table.select()):
users = connection.execute(
users_table.select().where(users_table.c.team_id == team.id).order_by(users_table.c.id).limit(1)
)
for user in users:
connection.execute(
teams_table.update().where(
teams_table.c.id == team.id
).values(
captain_id=user.id
)
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('team_captain_id', 'teams', type_='foreignkey')
op.drop_column('teams', 'captain_id')
# ### end Alembic commands ###