Files
stack/deploy/db_migrations/order-svc/0001_create_base_tables.up.sql
2025-11-23 21:49:18 +01:00

35 lines
1.1 KiB
SQL

CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE SCHEMA "order" AUTHORIZATION egommerce;
CREATE TABLE IF NOT EXISTS "order"."order"
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
"state" character varying NOT NULL DEFAULT 'new',
created_at timestamp without time zone NOT NULL DEFAULT now(),
updated_at timestamp without time zone,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS "order".order_item
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
order_id uuid NOT NULL,
product_id integer NOT NULL,
quantity integer NOT NULL DEFAULT 1,
price double precision NOT NULL DEFAULT 0.00,
created_at timestamp without time zone NOT NULL DEFAULT now(),
updated_at timestamp without time zone,
PRIMARY KEY (id)
);
ALTER TABLE IF EXISTS "order".order_item
ADD CONSTRAINT order_item_order_fkey FOREIGN KEY (order_id)
REFERENCES "ordering"."order" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS "order"."order" OWNER to egommerce;
ALTER TABLE IF EXISTS "order".order_item OWNER to egommerce;