Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Simple Build and BuildSequence models. #72

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions freight/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def deploy_config(self):
TaskConfig.type == TaskConfigType.deploy,
).first()

@property
def build_config(self):
from freight.models import TaskConfig, TaskConfigType
return TaskConfig.query.filter(
TaskConfig.app_id == self.id,
TaskConfig.type == TaskConfigType.build,
).first()

def get_default_ref(self, env):
data = self.environments.get(env)
if not data:
Expand Down
22 changes: 22 additions & 0 deletions freight/models/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import absolute_import

from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.schema import Index, UniqueConstraint

from freight.config import db


class Build(db.Model):
__tablename__ = 'build'
__table_args__ = (
Index('idx_build_task_id', 'task_id'),
Index('idx_build_app_id', 'app_id'),
UniqueConstraint('task_id', 'app_id', 'number', name='unq_build_number'),
)

id = Column(Integer, primary_key=True)
task_id = Column(Integer, ForeignKey('task.id', ondelete='CASCADE'),
nullable=False)
app_id = Column(Integer, ForeignKey('app.id', ondelete='CASCADE'),
nullable=False)
number = Column(Integer, nullable=False)
18 changes: 18 additions & 0 deletions freight/models/buildsequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import

from sqlalchemy import Column, Integer
from sqlalchemy.sql import func, select

from freight.config import db


class BuildSequence(db.Model):
__tablename__ = 'buildsequence'

app_id = Column(Integer, nullable=False, primary_key=True)
value = Column(Integer, default=0, server_default='0', nullable=False,
primary_key=True)

@classmethod
def get_clause(self, app_id):
return select([func.next_build_number(app_id)])
2 changes: 2 additions & 0 deletions freight/models/taskconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class TaskConfigType(object):
deploy = 0
build = 1

@classmethod
def get_label(cls, status):
Expand All @@ -21,6 +22,7 @@ def label_to_id(cls, label):

TYPE_LABELS = {
TaskConfigType.deploy: 'deploy',
TaskConfigType.build: 'build',
}
TYPE_LABELS_REV = {
v: k for k, v in TYPE_LABELS.items()
Expand Down
26 changes: 26 additions & 0 deletions migrations/versions/18ff76b912af_create_buildsequence_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Create buildsequence table.

Revision ID: 18ff76b912af
Revises: 493c6c33fa27
Create Date: 2016-05-05 14:47:50.243970
"""

# revision identifiers, used by Alembic.
revision = '18ff76b912af'
down_revision = '493c6c33fa27'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.create_table('buildsequence',
sa.Column('app_id', sa.Integer(), nullable=False),
sa.Column('value', sa.Integer(), server_default='0', nullable=False),
sa.PrimaryKeyConstraint('app_id', 'value')
)


def downgrade():
op.drop_table('buildsequence')
35 changes: 35 additions & 0 deletions migrations/versions/493c6c33fa27_create_build_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Create build table.

Revision ID: 493c6c33fa27
Revises: 205fd513c96
Create Date: 2016-05-05 14:31:38.491777
"""

# revision identifiers, used by Alembic.
revision = '493c6c33fa27'
down_revision = '205fd513c96'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.create_table('build',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('task_id', sa.Integer(), nullable=False),
sa.Column('app_id', sa.Integer(), nullable=False),
sa.Column('number', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['app_id'], ['app.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['task_id'], ['task.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('task_id', 'app_id', 'number', name='unq_build_number')
)
op.create_index('idx_build_app_id', 'build', ['app_id'], unique=False)
op.create_index('idx_build_task_id', 'build', ['task_id'], unique=False)


def downgrade():
op.drop_index('idx_build_task_id', table_name='build')
op.drop_index('idx_build_app_id', table_name='build')
op.drop_table('build')