ephraimbuddy commented on a change in pull request #21273:
URL: https://github.com/apache/airflow/pull/21273#discussion_r813648764



##########
File path: 
airflow/migrations/versions/7b2661a43ba3_taskinstance_keyed_to_dagrun.py
##########
@@ -337,7 +337,7 @@ def downgrade():
         batch_op.drop_constraint('task_instance_pkey', type_='primary')
         batch_op.alter_column('execution_date', existing_type=dt_type, 
existing_nullable=True, nullable=False)
         batch_op.alter_column(
-            'dag_id', existing_type=string_id_col_type, 
existing_nullable=True, nullable=True
+            'dag_id', existing_type=string_id_col_type, 
existing_nullable=True, nullable=False

Review comment:
       Here's the table before the upgrade that made `dag_id` non-nullable:
   
   ```
   airflow> sp_help task_instance                                               
   
   Time: 1.870s (a second)
   +---------------+---------+------------+-------------------------+
   | Name          | Owner   | Type       | Created_datetime        |
   |---------------+---------+------------+-------------------------|
   | task_instance | dbo     | user table | 2022-02-24 08:08:16.490 |
   +---------------+---------+------------+-------------------------+
    
   
+----------------------+-----------+------------+----------+--------+---------+-
   | Column_name          | Type      | Computed   | Length   | Prec   | Scale  
 | 
   
|----------------------+-----------+------------+----------+--------+---------+-
   | task_id              | varchar   | no         | 250      |        |        
 | 
   | dag_id               | varchar   | no         | 250      |        |        
 | 
   | execution_date       | datetime2 | no         | 8        | 26     | 6      
 | 
   | start_date           | datetime2 | no         | 8        | 26     | 6      
 | 
   | end_date             | datetime2 | no         | 8        | 26     | 6      
 | 
   | duration             | float     | no         | 8        | 53     | NULL   
 | 
   | state                | varchar   | no         | 20       |        |        
 | 
   | try_number           | int       | no         | 4        | 10     | 0      
 | 
   | hostname             | varchar   | no         | 1000     |        |        
 | 
   | unixname             | varchar   | no         | 1000     |        |        
 | 
   | job_id               | int       | no         | 4        | 10     | 0      
 | 
   | pool                 | varchar   | no         | 256      |        |        
 | 
   | queue                | varchar   | no         | 256      |        |        
 | 
   | priority_weight      | int       | no         | 4        | 10     | 0      
 | 
   | operator             | varchar   | no         | 1000     |        |        
 | 
   :
   | queued_dttm          | datetime2 | no         | 8        | 26     | 6      
 | 
   :
   | pid                  | int       | no         | 4        | 10     | 0      
 | 
   :
   | max_tries            | int       | no         | 4        | 10     | 0      
 | 
   :
   | executor_config      | varbinary | no         | -1       |        |        
 | 
   :
   | pool_slots           | int       | no         | 4        | 10     | 0      
 | 
   :
   | queued_by_job_id     | int       | no         | 4        | 10     | 0      
 | 
   :
   | external_executor_id | varchar   | no         | 250      |        |        
 | 
   | trigger_id           | int       | no         | 4        | 10     | 0      
 | 
   :
   | trigger_timeout      | datetime  | no         | 8        |        |        
 | 
   :
   | next_method          | varchar   | no         | 1000     |        |        
 | 
   :
   | next_kwargs          | nvarchar  | no         | -1       |        |        
 | 
   
+----------------------+-----------+------------+----------+--------+---------+-
   :
    
   :
   
+-----------------------------+--------+-------------+-----------------------+
   :
   | Identity                    | Seed   | Increment   | Not For Replication   
|
   :
   
|-----------------------------+--------+-------------+-----------------------|
   :
   | No identity column defined. | NULL   | NULL        | NULL                  
|
   :
   
+-----------------------------+--------+-------------+-----------------------+
    
   :
   +-------------------------------+
   :
   | RowGuidCol                    |
   :
   |-------------------------------|
   | No rowguidcol column defined. |
   :
   +-------------------------------+
    
   :
   +-----------------------------+
   :
   | Data_located_on_filegroup   |
   :
   |-----------------------------|
   :
   | PRIMARY                     |
   :
   +-----------------------------+
    
   :
   
+--------------------------------+----------------------------------------------
   :
   | index_name                     | index_description                         
   
   :
   
|--------------------------------+----------------------------------------------
   :
   | PK__task_ins__9BEABD042B51623C | clustered, unique, primary key located on 
PRI
   | ti_dag_date                    | nonclustered located on PRIMARY           
   
   :
   | ti_dag_state                   | nonclustered located on PRIMARY           
   
   | ti_job_id                      | nonclustered located on PRIMARY           
   
   :
   | ti_pool                        | nonclustered located on PRIMARY           
   
   | ti_state                       | nonclustered located on PRIMARY           
   
   :
   | ti_state_lkp                   | nonclustered located on PRIMARY           
   
   :
   | ti_trigger_id                  | nonclustered located on PRIMARY           
   
   
+--------------------------------+----------------------------------------------
   :
    
   :
   
+------------------------------+--------------------------------+---------------
   | constraint_type              | constraint_name                | 
delete_action 
   :
   
|------------------------------+--------------------------------+---------------
   :
   | DEFAULT on column max_tries  | DF__task_inst__max_t__5AEE82B9 | (n/a)      
   
   :
   | DEFAULT on column pool_slots | DF__task_inst__pool___17036CC0 | (n/a)      
   
   :
   | PRIMARY KEY (clustered)      | PK__task_ins__9BEABD042B51623C | (n/a)      
   
   :
   | FOREIGN KEY                  | task_instance_trigger_id_fkey  | Cascade    
   
   :
   |                              |                                |            
   
   
+------------------------------+--------------------------------+---------------
   :
    
   :
   +-----------------------------------------------------------------+
   :
   | Table is referenced by foreign key                              |
   :
   |-----------------------------------------------------------------|
   :
   | airflow.dbo.task_reschedule: task_reschedule_dag_task_date_fkey |
   :
   +-----------------------------------------------------------------+
   ```
   So `dag_id` wasn't nullable in MSSQL before the upgrade




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