Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

Database deployments fail on rerun with "object already exists" errors, preventing iterative updates and CI/CD workflows.

Changes

18 SQL table scripts modified to use existence checks:

  • Main artifacts: DeploymentComponents/azure_sql_artifacts/tables/ (8 files)
  • Consumer artifacts: beneficial_ownership, generic, acts (10 files)

Pattern applied:

-- Before
CREATE TABLE [dbo].[IngestedSourceDataAudit](...);
GO
ALTER TABLE [dbo].[IngestedSourceDataAudit] ADD CONSTRAINT [DF_ValidFrom] ...;
GO

-- After
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[IngestedSourceDataAudit]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[IngestedSourceDataAudit](...);

IF NOT EXISTS (SELECT * FROM sys.default_constraints WHERE name = 'DF_ValidFrom' AND parent_object_id = OBJECT_ID('[dbo].[IngestedSourceDataAudit]'))
BEGIN
ALTER TABLE [dbo].[IngestedSourceDataAudit] ADD CONSTRAINT [DF_ValidFrom] ...;
END
END
GO

Handles temporal tables with SYSTEM_VERSIONING, primary keys, and default constraints. Stored procedures already use CREATE OR ALTER and require no changes.

Documentation

Updated azure_sql_artifacts/README.md to document idempotent deployment capability.

Original prompt

This section details on the original issue you should resolve

<issue_title>Database deployment not working</issue_title>
<issue_description>Hello

I'm trying to deploy the solution however, when I try to update changes in the SQL database I have the following error

There is already an object named 'IngestedSourceDataAudit' in the database.

Is the solution not intended to ongoing updates?</issue_description>

<agent_instructions>Assess the reasons for the user getting the 'There is already an object named 'IngestedSourceDataAudit' in the database' . error when trying to deploy the solution. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 10, 2025 13:49
Co-authored-by: mswantek68 <46489667+mswantek68@users.noreply.github.com>
Co-authored-by: mswantek68 <46489667+mswantek68@users.noreply.github.com>
Co-authored-by: mswantek68 <46489667+mswantek68@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix database deployment not working due to object conflict Make SQL table creation scripts idempotent to support redeployment Nov 10, 2025
Copilot AI requested a review from mswantek68 November 10, 2025 14:03
Copilot finished work on behalf of mswantek68 November 10, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database deployment not working

2 participants