sql-yodeler-example-postgres

Postgres, 5 objects, from chant build of the declared schema. Written by yodel docs.

Objects

Entity relationships

Mermaid source; erd.md next to this file renders it on GitHub, GitLab and Forgejo.

erDiagram
  shop_orders["shop.orders"] {
    bigint id PK
    text email
    text status
    numeric(12_2) amount
    timestamp_with_time_zone placed_at
    timestamp_with_time_zone refunded_at
    boolean gift
  }

Reference

shopPostgres::Schema, export shopSchema

The SQL Yodeler Postgres example

History

MigrationStep
20261010T1723-baselineSQLPG200 create: CREATE SCHEMA shop
20261010T1723-baselineSQLPG200 create: COMMENT ON SCHEMA shop IS 'The SQL Yodeler Postgres example [chant managed-by=chant]'
DDL
CREATE SCHEMA shop;
  COMMENT ON SCHEMA shop IS 'The SQL Yodeler Postgres example'

shop.ordersPostgres::Table, export orders

Primary key
(id) orders_pkey
Check
amount > 0 orders_amount_positive
ColumnTypeNullKeyDefaultComment
idbigintyesPKGENERATED ALWAYS AS IDENTITY
emailtextno
statustextnoDEFAULT 'placed'::text
amountnumeric(12,2)no
placed_attimestamp with time zonenoDEFAULT now()
refunded_attimestamp with time zoneyes
giftbooleannoDEFAULT false

History

MigrationStep
20261010T1723-baselineSQLPG200 create: CREATE TABLE shop.orders ( id bigint GENERATED ALWAYS AS IDENTITY, customer_email text NOT NULL, status text DEFAULT 'placed'::text NOT NULL, amount numeric(12,2) NOT NULL, placed_at timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT orders_pkey PRIMARY KEY (id) )
20261010T1723-baselineSQLPG200 create: COMMENT ON TABLE shop.orders IS '[chant managed-by=chant]'
20261010T1723-couponsSQLPG201 metadata: ALTER TABLE shop.orders ADD COLUMN coupon text
20261010T1723-couponsSQLPG217 metadata: ALTER TABLE shop.orders ADD CONSTRAINT orders_amount_positive CHECK (amount > 0) NOT VALID
20261010T1723-couponsSQLPG220 validate: ALTER TABLE shop.orders VALIDATE CONSTRAINT orders_amount_positive
20261010T1724-refundsSQLPG201 metadata: ALTER TABLE shop.orders ADD COLUMN refunded_at timestamp with time zone
20261010T1724-rename-emailPostgresMigrationOp step (SQLPG205 columns.email)
20261010T1724-drop-couponSQLPG204 metadata: ALTER TABLE shop.orders DROP COLUMN coupon
20261010T1725-add-giftSQLPG201 metadata: ALTER TABLE shop.orders ADD COLUMN gift boolean DEFAULT false NOT NULL
DDL
CREATE TABLE shop.orders (
      id bigint GENERATED ALWAYS AS IDENTITY,
      email text NOT NULL, -- previously: customer_email
      status text DEFAULT 'placed'::text NOT NULL,
      amount numeric(12,2) NOT NULL,
      placed_at timestamp with time zone DEFAULT now() NOT NULL,
      refunded_at timestamp with time zone,
      gift boolean DEFAULT false NOT NULL,
      CONSTRAINT orders_pkey PRIMARY KEY (id),
      CONSTRAINT orders_amount_positive CHECK (amount > 0)
  )

shop.orders_placed_at_idxPostgres::Index, export ordersPlacedAt

On
shop.orders (placed_at)

History

MigrationStep
20261010T1725-index-placed-atSQLPG240 concurrently: CREATE INDEX CONCURRENTLY orders_placed_at_idx ON shop.orders (placed_at)
20261010T1725-index-placed-atSQLPG240 concurrently: COMMENT ON INDEX shop.orders_placed_at_idx IS '[chant managed-by=chant]'
DDL
CREATE INDEX CONCURRENTLY orders_placed_at_idx ON shop.orders (placed_at)

shop.orders_refunded_at_idxPostgres::Index, export ordersRefundedAt

On
shop.orders (refunded_at)

History

MigrationStep
20261010T1724-refundsSQLPG240 concurrently: CREATE INDEX CONCURRENTLY orders_refunded_at_idx ON shop.orders (refunded_at)
20261010T1724-refundsSQLPG240 concurrently: COMMENT ON INDEX shop.orders_refunded_at_idx IS '[chant managed-by=chant]'
DDL
CREATE INDEX CONCURRENTLY orders_refunded_at_idx ON shop.orders (refunded_at)

shop.orders_status_idxPostgres::Index, export ordersStatusIdx

On
shop.orders (status) using btree

History

MigrationStep
20261010T1723-baselineSQLPG200 create: CREATE INDEX orders_status_idx ON shop.orders USING btree (status)
20261010T1723-baselineSQLPG200 create: COMMENT ON INDEX shop.orders_status_idx IS '[chant managed-by=chant]'
DDL
CREATE INDEX orders_status_idx ON shop.orders USING btree (status)