Skip to content
Merged
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 UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ https://developers.google.com/style/inclusive-documentation

-->

### Not-nullable conn_type collumn in connection table

The `conn_type` column in the `connection` table must contain content. Previously, this rule was enforced
by application logic, but was not enforced by the database schema.

If you made any modifications to the table directly, make sure you don't have
null in the conn_type column.

### DAG.create_dagrun accepts run_type and does not require run_id
This change is caused by adding `run_type` column to `DagRun`.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

"""Set conn_type as non-nullable

Revision ID: 8f966b9c467a
Revises: 3c20cacc0044
Create Date: 2020-06-08 22:36:34.534121

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "8f966b9c467a"
down_revision = "3c20cacc0044"
branch_labels = None
depends_on = None


def upgrade():
"""Apply Set conn_type as non-nullable"""

with op.batch_alter_table("connection", schema=None) as batch_op:
batch_op.alter_column("conn_type", existing_type=sa.VARCHAR(length=500), nullable=False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work without default value? I'm aware that there should be no connection without type but what if?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this happens, the migration will fail and the user will have to manually correct the data. The user will receive information on the specific migration, so user will be able to easily determine the source of the problem. I do not want to modify this table because the user may have had different assumptions based on this field. Airflow has always required this field not to be null. Only various hacks of the user could lead to this state, so he will best know the solution to this problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this sounds good to me -- there's no "sensible default" we could choose to put in this column, so the user will need to manually fix this up.



def downgrade():
"""Unapply Set conn_type as non-nullable"""
with op.batch_alter_table("connection", schema=None) as batch_op:
batch_op.alter_column("conn_type", existing_type=sa.VARCHAR(length=500), nullable=True)
2 changes: 1 addition & 1 deletion airflow/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Connection(Base, LoggingMixin):

id = Column(Integer(), primary_key=True)
conn_id = Column(String(ID_LEN))
conn_type = Column(String(500))
conn_type = Column(String(500), nullable=False)
host = Column(String(500))
schema = Column(String(500))
login = Column(String(500))
Expand Down