#
# Copyright (C) 2022 Red Hat, Inc
#
# Licensed 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.

"""sync database

Revision ID: 980e18983453
Revises: 24963e101d13
Create Date: 2022-02-27 02:35:02.516736

"""

# revision identifiers, used by Alembic.
revision = "980e18983453"
down_revision = "24963e101d13"
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


def upgrade():
    op.alter_column(
        "components", "etag", existing_type=sa.VARCHAR(length=40), nullable=False
    )
    op.alter_column(
        "components", "updated_at", existing_type=postgresql.TIMESTAMP(), nullable=False
    )


def downgrade():
    op.alter_column(
        "components", "updated_at", existing_type=postgresql.TIMESTAMP(), nullable=True
    )
    op.alter_column(
        "components", "etag", existing_type=sa.VARCHAR(length=40), nullable=True
    )

Set etag and updated_at components fields not nullable
Set etag and updated_at components fields not nullable

Today in production database updated_at and etag are nullable.

                    Table "public.components"
         Column         |            Type             | Modifiers
------------------------+-----------------------------+-----------
 updated_at             | timestamp without time zone |
 etag                   | character varying(40)       |

But in the code they are not.

In this patch we alter the column to set those 2 fields nullable to False.

Change-Id: I2dc4d184d02c8adde1684df1b62c8269a30fb0b1
