|
| 1 | +# flake8: noqa |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +"""add task_reschedule table |
| 21 | +
|
| 22 | +Revision ID: 0a2a5b66e19d |
| 23 | +Revises: 9635ae0956e7 |
| 24 | +Create Date: 2018-06-17 22:50:00.053620 |
| 25 | +
|
| 26 | +""" |
| 27 | + |
| 28 | +# revision identifiers, used by Alembic. |
| 29 | +revision = '0a2a5b66e19d' |
| 30 | +down_revision = '9635ae0956e7' |
| 31 | +branch_labels = None |
| 32 | +depends_on = None |
| 33 | + |
| 34 | +from alembic import op |
| 35 | +import sqlalchemy as sa |
| 36 | +from sqlalchemy.dialects import mysql |
| 37 | + |
| 38 | + |
| 39 | +TABLE_NAME = 'task_reschedule' |
| 40 | +INDEX_NAME = 'idx_' + TABLE_NAME + '_dag_task_date' |
| 41 | + |
| 42 | +# For Microsoft SQL Server, TIMESTAMP is a row-id type, |
| 43 | +# having nothing to do with date-time. DateTime() will |
| 44 | +# be sufficient. |
| 45 | +def mssql_timestamp(): |
| 46 | + return sa.DateTime() |
| 47 | + |
| 48 | +def mysql_timestamp(): |
| 49 | + return mysql.TIMESTAMP(fsp=6) |
| 50 | + |
| 51 | +def sa_timestamp(): |
| 52 | + return sa.TIMESTAMP(timezone=True) |
| 53 | + |
| 54 | +def upgrade(): |
| 55 | + # See 0e2a74e0fc9f_add_time_zone_awareness |
| 56 | + conn = op.get_bind() |
| 57 | + if conn.dialect.name == 'mysql': |
| 58 | + timestamp = mysql_timestamp |
| 59 | + elif conn.dialect.name == 'mssql': |
| 60 | + timestamp = mssql_timestamp |
| 61 | + else: |
| 62 | + timestamp = sa_timestamp |
| 63 | + |
| 64 | + op.create_table( |
| 65 | + TABLE_NAME, |
| 66 | + sa.Column('id', sa.Integer(), nullable=False), |
| 67 | + sa.Column('task_id', sa.String(length=250), nullable=False), |
| 68 | + sa.Column('dag_id', sa.String(length=250), nullable=False), |
| 69 | + # use explicit server_default=None otherwise mysql implies defaults for first timestamp column |
| 70 | + sa.Column('execution_date', timestamp(), nullable=False, server_default=None), |
| 71 | + sa.Column('try_number', sa.Integer(), nullable=False), |
| 72 | + sa.Column('start_date', timestamp(), nullable=False), |
| 73 | + sa.Column('end_date', timestamp(), nullable=False), |
| 74 | + sa.Column('duration', sa.Integer(), nullable=False), |
| 75 | + sa.Column('reschedule_date', timestamp(), nullable=False), |
| 76 | + sa.PrimaryKeyConstraint('id'), |
| 77 | + sa.ForeignKeyConstraint(['task_id', 'dag_id', 'execution_date'], |
| 78 | + ['task_instance.task_id', 'task_instance.dag_id','task_instance.execution_date'], |
| 79 | + name='task_reschedule_dag_task_date_fkey') |
| 80 | + ) |
| 81 | + op.create_index( |
| 82 | + INDEX_NAME, |
| 83 | + TABLE_NAME, |
| 84 | + ['dag_id', 'task_id', 'execution_date'], |
| 85 | + unique=False |
| 86 | + ) |
| 87 | + |
| 88 | + |
| 89 | +def downgrade(): |
| 90 | + op.drop_index(INDEX_NAME, table_name=TABLE_NAME) |
| 91 | + op.drop_table(TABLE_NAME) |
0 commit comments