syun64 commented on code in PR #34335:
URL: https://github.com/apache/airflow/pull/34335#discussion_r1324812387


##########
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py:
##########
@@ -43,7 +43,7 @@ def upgrade():
             sa.Column(
                 "clear_number",
                 sa.Integer,
-                default=0,
+                server_default="0",

Review Comment:
   I've had to spend some time figuring out how to make this work with MSSQL, 
and I think this is an approach that 'works':
   
   https://github.com/apache/airflow/pull/34344/files - the PR is currently 
failing because of failing ER diagram and black pre-commit checks, but the 
Migration CI seems to be working. I don't have access to my laptop right now, 
but will be able to fix the pre-commit check later this evening... or 
@abhishekbhakat feel free to adopt the logic into this PR to merge it in, if 
you are able to get to it faster than I am 👍 
   
   Other seemingly more 'correct' ways of handling the migration for MSSQL were 
failing.
   
   For example, using the following drop_column command still fails for MSSQL: 
   
   `batch_op.drop_column("clear_number", mssql_drop_default=True)`
   
   ```
   sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', 
"[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Incorrect syntax 
near 'constraint'. (102) (SQLExecDirectW)")
   [SQL: declare @const_name varchar(256)
   select @const_name = QUOTENAME([name]) from sys.default_constraints
   where parent_object_id = object_id('dag_run')
   and col_name(parent_object_id, parent_column_id) = 'clear_number'
   exec('alter table dag_run drop constraint ' + @const_name)]
   ```
   



##########
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py:
##########
@@ -43,7 +43,7 @@ def upgrade():
             sa.Column(
                 "clear_number",
                 sa.Integer,
-                default=0,
+                server_default="0",

Review Comment:
   I've had to spend some time figuring out how to make this work with MSSQL, 
and I think this is an approach that 'works':
   
   https://github.com/apache/airflow/pull/34344/files - the PR is currently 
failing because of failing ER diagram and black pre-commit checks, but the 
Migration CI seems to be working. I don't have access to my laptop right now, 
but will be able to fix the pre-commit check later this evening... or 
@abhishekbhakat feel free to adopt the logic into this PR to merge it in, if 
you are able to get to it faster than I am 👍 
   
   Other seemingly more 'correct' ways of handling the migration for MSSQL were 
failing.
   
   For example, using the following drop_column command still fails for MSSQL: 
   
   `batch_op.drop_column("clear_number", mssql_drop_default=True)`
   
   ```
   sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', 
"[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Incorrect syntax 
near 'constraint'. (102) (SQLExecDirectW)")
   [SQL: declare @const_name varchar(256)
   select @const_name = QUOTENAME([name]) from sys.default_constraints
   where parent_object_id = object_id('dag_run')
   and col_name(parent_object_id, parent_column_id) = 'clear_number'
   exec('alter table dag_run drop constraint ' + @const_name)]
   ```
   



-- 
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]

Reply via email to