def define_workers_table(meta): workers = Table('workers', meta, Column('id', String(36), primary_key=True, nullable=False), Column('host', String(255), nullable=False), Column('process_id', Integer(), nullable=True), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) return workers
def define_schedules_table(meta): schedules = Table('schedules', meta, Column('id', String(36), primary_key=True, nullable=False), Column('tenant', String(255), nullable=False), Column('action', String(255), nullable=False), Column('minute', Integer(), nullable=True), Column('hour', Integer(), nullable=True), Column('day_of_month', Integer(), nullable=True), Column('month', Integer(), nullable=True), Column('day_of_week', Integer(), nullable=True), Column('last_scheduled', DateTime(), nullable=True), Column('next_run', DateTime(), nullable=True), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) return schedules
def define_job_metadata_table(meta): (define_jobs_table,) = from_migration_import( '004_add_jobs_table', ['define_jobs_table']) jobs = define_jobs_table(meta) # NOTE(dperaza) DB2: specify the UniqueConstraint option when creating # the table will cause an index being created to specify the index # name and skip the step of creating another index with the same columns. # The index name is needed so it can be dropped and re-created later on. constr_kwargs = {} if meta.bind.name == 'ibm_db_sa': constr_kwargs['name'] = 'ix_job_metadata_job_id_key' job_metadata = Table('job_metadata', meta, Column('id', String(36), primary_key=True, nullable=False), Column('job_id', String(36), ForeignKey(jobs.c.id), nullable=False), Column('key', String(255), nullable=False), Column('value', Text(), nullable=False), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), UniqueConstraint('job_id', 'key', **constr_kwargs), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) return job_metadata
def get_jobs_table(meta): jobs = Table('jobs', meta, Column('id', String(36), primary_key=True, nullable=False), Column('schedule_id', String(36)), Column('tenant', String(255), nullable=False), Column('worker_id', String(36), nullable=True), Column('status', String(255), nullable=True), Column('action', String(255), nullable=False), Column('retry_count', Integer(), nullable=False, default=0), Column('timeout', DateTime(), nullable=False), Column('hard_timeout', DateTime(), nullable=False), Column('version_id', String(36)), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) return jobs
def define_job_faults_table(meta): job_faults = Table('job_faults', meta, Column('id', String(36), primary_key=True, nullable=False), Column('job_id', String(36), nullable=False), Column('schedule_id', String(36), nullable=False), Column('tenant', String(255), nullable=False), Column('worker_id', String(36), nullable=False), Column('action', String(255), nullable=False), Column('message', String(255), nullable=True), Column('job_metadata', Text(), nullable=True), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime(), nullable=False), mysql_engine='InnoDB', mysql_charset='utf8', extend_existing=True) return job_faults
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from sqlalchemy.schema import Column from sqlalchemy.schema import MetaData from sqlalchemy.schema import Table from qonos.db.sqlalchemy.migrate_repo.schema import String meta = MetaData() version = Column('version_id', String(36)) def upgrade(migrate_engine): meta.bind = migrate_engine jobs = Table('jobs', meta, autoload=True) jobs.create_column(version) def downgrade(migrate_engine): meta.bind = migrate_engine jobs = Table('jobs', meta, autoload=True) jobs.drop_column(version)