Skip to content

Add support for CREATE SCHEMA - #99

Open
ateirney-nz wants to merge 1 commit into
daichirata:masterfrom
ateirney-nz:feat/create-schema-support
Open

Add support for CREATE SCHEMA#99
ateirney-nz wants to merge 1 commit into
daichirata:masterfrom
ateirney-nz:feat/create-schema-support

Conversation

@ateirney-nz

Copy link
Copy Markdown
Contributor

Summary

Adds support for CREATE SCHEMA (named schemas) to the diff engine so that schema definitions using named schemas can be exported, diffed, and applied.

Changes

  • Model CREATE SCHEMA in the diff engine (NewDatabase): collect *ast.CreateSchema statements into a new schemas set and a Schema wrapper type, instead of erroring on the unrecognised statement.
  • Diff generation (GenerateDDL):
    • Schemas present in the target but not the source are emitted as CREATE SCHEMA before any tables — so the schema exists before objects are created inside it.
    • Schemas present in the source but not the target are emitted as DROP SCHEMA last — after every object inside them has been dropped.
  • --ignore-create-schema flag (and IgnoreCreateSchema option) added to apply, create, diff, and export, for parity with the existing --ignore-* flags.

Ordering

Verified that schema-qualified objects diff and order correctly in both directions:

  • Create: CREATE SCHEMA → table → index → view
  • Drop: index → table → view → DROP SCHEMA

Tests

  • TestParseDDL: ignore-create-schema case.
  • TestDiff: create/drop schema, no-op when unchanged, and ordering relative to schema-qualified tables, indexes, and views.

go build ./..., go vet ./..., and go test ./... all pass.

Model CREATE SCHEMA in the diff engine: create schemas before any
object that may live inside them and drop them after their contents.
Add an --ignore-create-schema flag (and IgnoreCreateSchema option) for
parity with the other ignore flags.
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