Chais commented on code in PR #58149:
URL: https://github.com/apache/airflow/pull/58149#discussion_r2694214077
##########
airflow-core/src/airflow/migrations/versions/0060_3_0_0_add_try_id_to_ti_and_tih.py:
##########
@@ -127,34 +127,8 @@ def upgrade():
def downgrade():
"""Unapply Add try_id to TI and TIH."""
- dialect_name = op.get_bind().dialect.name
with op.batch_alter_table("task_instance_history", schema=None) as
batch_op:
batch_op.drop_constraint(batch_op.f("task_instance_history_pkey"),
type_="primary")
- batch_op.add_column(sa.Column("id", sa.INTEGER, nullable=True))
+ batch_op.add_column(sa.Column("id", sa.INTEGER, primary_key=True,
autoincrement=True))
Review Comment:
I'm not convinced this is the case. The downgrade SQL generated for psql
looks like this:
```sql
BEGIN;
-- Running downgrade 7645189f3479 -> e00344393f31
ALTER TABLE task_instance_history DROP CONSTRAINT task_instance_history_pkey;
ALTER TABLE task_instance_history ADD COLUMN id SERIAL NOT NULL;
ALTER TABLE task_instance_history DROP COLUMN task_instance_id;
ALTER TABLE task_instance_history DROP COLUMN try_id;
UPDATE alembic_version SET version_num='e00344393f31' WHERE
alembic_version.version_num = '7645189f3479';
COMMIT;
```
The relevant line is:
```sql
ALTER TABLE task_instance_history ADD COLUMN id SERIAL NOT NULL;
```
If I now create a test table and fill it with some data:
```sql
CREATE TABLE test ( column_a text, column_b integer );
INSERT INTO test (column_a, column_b) VALUES ('some text', 3);
postgres=# INSERT INTO test (column_a, column_b) VALUES ('some other text',
17);
```
I see it as expected:
```
SELECT * FROM test;
column_a | column_b
-----------------+----------
some text | 3
some other text | 17
(2 rows)
```
If I now apply the relevant change to this table with its existing data like
this:
```sql
ALTER TABLE test ADD COLUMN id SERIAL NOT NULL;
```
I can see the values being inserted:
```
SELECT * FROM test;
column_a | column_b | id
-----------------+----------+----
some text | 3 | 1
some other text | 17 | 2
(2 rows)
```
So this seems to work as intended on PostgreSQL. I tested it on MySQL when I
wrote this PR, with a similar result.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]