dast_site_profiles created during pipeline creation causes CrossDatabaseModificationAcrossUnsupportedTablesError

Per https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions we do not allow you to write to 2 different databases within the context of a single transaction. When a pipeline is created we are opening a transaction and writing to the ci_pipelines, ... tables but we're also inserting into dast_site_profiles which violates this rule:

2) Ci::CreatePipelineService when the feature is licensed when the stage is not dast behaves like it does not expand the dast variables does not include the profile variables                         
     Failure/Error:                                                                                                                                                                                      
       raise Database::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError,                                                                                          
         "Cross-database data modification of '#{schemas.to_a.join(", ")}' were detected within " \                                                                                                      
         "a transaction modifying the '#{all_tables.to_a.join(", ")}' tables." \                                                                                                                         
         "Please refer to https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions for details on how to resolve this exception."                    
                                                                                                                                                                                                         
     Database::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError:                                                                                                  
       Cross-database data modification of 'gitlab_ci, gitlab_main' were detected within a transaction modifying the 'ci_pipelines, ci_stages, ci_builds, ci_builds_metadata, dast_site_profiles_builds' 
tables.Please refer to https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions for details on how to resolve this exception.    

For now we have added these dast_site_profiles violations in allowlist https://gitlab.com/gitlab-org/gitlab/-/blob/93803cc03d97f48e3cad9d300119b0a9a1ace6cc/spec/support/database/cross-database-modification-allowlist.yml#L450 .

It seems the problem with this case is that we build a pipeline.dast_profile at some point during pipeline creation and then when we call pipeline.save! it tries to save the dast_profile in the same transaction.

Possible solutions

See https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions .

Likely the easiest option will be to make the dast_profile save after commit.