mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-25 03:01:51 +08:00
Add owner and timestamp columns to the module_builds table
This commit is contained in:
committed by
Nils Philippsen
parent
1cd21434fb
commit
d1a01e5d79
41
migrations/versions/1a44272e8b4c_.py
Normal file
41
migrations/versions/1a44272e8b4c_.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
"""Adds the owner, time_completed, time_modified, and time_submitted columns to the module_builds table
|
||||||
|
|
||||||
|
Revision ID: 1a44272e8b4c
|
||||||
|
Revises: a7a553e5ca1d
|
||||||
|
Create Date: 2016-08-17 17:00:31.126429
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '1a44272e8b4c'
|
||||||
|
down_revision = 'a7a553e5ca1d'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
epoch = datetime.utcfromtimestamp(0).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('module_builds', sa.Column('owner', sa.String(), server_default='Unknown User', nullable=False))
|
||||||
|
op.add_column('module_builds', sa.Column('time_completed', sa.DateTime(), nullable=True, server_default=epoch))
|
||||||
|
op.add_column('module_builds', sa.Column('time_modified', sa.DateTime(), nullable=True, server_default=epoch))
|
||||||
|
op.add_column('module_builds', sa.Column('time_submitted', sa.DateTime(), nullable=False, server_default=epoch))
|
||||||
|
|
||||||
|
# Remove migration-only defaults. Using batch_alter_table() recreates the table instead of using ALTER COLUMN
|
||||||
|
# on simplistic DB engines. Thanks SQLite!
|
||||||
|
with op.batch_alter_table('module_builds') as b:
|
||||||
|
b.alter_column('owner', server_default=None)
|
||||||
|
b.alter_column('time_completed', server_default=None)
|
||||||
|
b.alter_column('time_modified', server_default=None)
|
||||||
|
b.alter_column('time_submitted', server_default=None)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# Thanks again!
|
||||||
|
with op.batch_alter_table('module_builds') as b:
|
||||||
|
b.drop_column('time_submitted')
|
||||||
|
b.drop_column('time_modified')
|
||||||
|
b.drop_column('time_completed')
|
||||||
|
b.drop_column('owner')
|
||||||
@@ -25,12 +25,11 @@
|
|||||||
|
|
||||||
""" SQLAlchemy Database models for the Flask app
|
""" SQLAlchemy Database models for the Flask app
|
||||||
"""
|
"""
|
||||||
|
from datetime import datetime
|
||||||
from rida import db, log
|
|
||||||
from sqlalchemy.orm import validates
|
from sqlalchemy.orm import validates
|
||||||
|
|
||||||
import modulemd as _modulemd
|
import modulemd as _modulemd
|
||||||
|
|
||||||
|
from rida import db, log
|
||||||
import rida.messaging
|
import rida.messaging
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +82,10 @@ class ModuleBuild(RidaBase):
|
|||||||
modulemd = db.Column(db.String, nullable=False)
|
modulemd = db.Column(db.String, nullable=False)
|
||||||
koji_tag = db.Column(db.String) # This gets set after 'wait'
|
koji_tag = db.Column(db.String) # This gets set after 'wait'
|
||||||
scmurl = db.Column(db.String)
|
scmurl = db.Column(db.String)
|
||||||
|
owner = db.Column(db.String, nullable=False)
|
||||||
|
time_submitted = db.Column(db.DateTime, nullable=False)
|
||||||
|
time_modified = db.Column(db.DateTime)
|
||||||
|
time_completed = db.Column(db.DateTime)
|
||||||
|
|
||||||
# A monotonically increasing integer that represents which batch or
|
# A monotonically increasing integer that represents which batch or
|
||||||
# iteration this module is currently on for successive rebuilds of its
|
# iteration this module is currently on for successive rebuilds of its
|
||||||
@@ -125,7 +128,8 @@ class ModuleBuild(RidaBase):
|
|||||||
return session.query(cls).filter(cls.id==event['msg']['id']).first()
|
return session.query(cls).filter(cls.id==event['msg']['id']).first()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, session, conf, name, version, release, modulemd, scmurl):
|
def create(cls, session, conf, name, version, release, modulemd, scmurl, username):
|
||||||
|
now = datetime.utcnow()
|
||||||
module = cls(
|
module = cls(
|
||||||
name=name,
|
name=name,
|
||||||
version=version,
|
version=version,
|
||||||
@@ -133,6 +137,9 @@ class ModuleBuild(RidaBase):
|
|||||||
state="init",
|
state="init",
|
||||||
modulemd=modulemd,
|
modulemd=modulemd,
|
||||||
scmurl=scmurl,
|
scmurl=scmurl,
|
||||||
|
owner=username,
|
||||||
|
time_submitted=now,
|
||||||
|
time_modified=now
|
||||||
)
|
)
|
||||||
session.add(module)
|
session.add(module)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ def submit_build():
|
|||||||
release=mmd.release,
|
release=mmd.release,
|
||||||
modulemd=yaml,
|
modulemd=yaml,
|
||||||
scmurl=url,
|
scmurl=url,
|
||||||
|
username=username
|
||||||
)
|
)
|
||||||
|
|
||||||
def failure(message, code):
|
def failure(message, code):
|
||||||
|
|||||||
Reference in New Issue
Block a user