Skip to content

Make schema creation idempotent for weekly index#11

Merged
Gabrielebattimelli merged 1 commit into
mainfrom
add-agent-skill
Jun 2, 2026
Merged

Make schema creation idempotent for weekly index#11
Gabrielebattimelli merged 1 commit into
mainfrom
add-agent-skill

Conversation

@Gabrielebattimelli
Copy link
Copy Markdown
Member

Why

After the LOG_* fix (#10), the Weekly Index run got past import but failed at the Create/update schema step:

psycopg.errors.DuplicateTable: relation "module" already exists
  File ".../database/create_schema.py", line 114, in create_schema

The pipeline runs database schema every week against the existing production DB, but the CREATE statements were unconditional.

What

Make create_schema idempotent so re-running is a no-op:

  • CREATE TABLE / CREATE SCHEMA... IF NOT EXISTS
  • CREATE VIEW recordCREATE OR REPLACE VIEW
  • enum types → DO $$ ... EXCEPTION WHEN duplicate_object THEN null; END $$ (Postgres CREATE TYPE has no IF NOT EXISTS)

The connection runs with autocommit=True, so each statement is independent.

The weekly index pipeline runs 'database schema' every week against the
existing production DB, but the CREATE statements were unconditional and
failed with DuplicateTable. Use IF NOT EXISTS for tables/schema, CREATE
OR REPLACE for the view, and a DO/duplicate_object block for enum types
(CREATE TYPE has no IF NOT EXISTS).
Copilot AI review requested due to automatic review settings June 2, 2026 10:44
@Gabrielebattimelli Gabrielebattimelli merged commit 1563985 into main Jun 2, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Makes the create_schema function idempotent so the weekly index job can re-run against an existing production database without failing on duplicate-object errors.

Changes:

  • Adds IF NOT EXISTS to CREATE TABLE and CREATE SCHEMA statements.
  • Switches the record view to CREATE OR REPLACE VIEW.
  • Wraps CREATE TYPE enum statements in DO $$ ... EXCEPTION WHEN duplicate_object THEN null; END $$ blocks since Postgres lacks CREATE TYPE IF NOT EXISTS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants