stack/deploy/db_migrations/order-svc/0001_create_base_tables.up.sql

34 lines
1.0 KiB
MySQL
Raw Permalink Normal View History

2024-12-24 14:29:04 +01:00
CREATE TABLE IF NOT EXISTS "ordering"."order"
2022-12-25 23:21:27 +01:00
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
2024-12-24 14:29:04 +01:00
"state" character varying NOT NULL DEFAULT 'new',
2022-12-25 23:21:27 +01:00
created_at timestamp without time zone NOT NULL DEFAULT now(),
updated_at timestamp without time zone,
PRIMARY KEY (id)
);
2024-12-24 14:29:04 +01:00
CREATE TABLE IF NOT EXISTS "ordering".order_item
2022-12-25 23:21:27 +01:00
(
id uuid NOT NULL DEFAULT gen_random_uuid(),
order_id uuid NOT NULL,
product_id integer NOT NULL,
quantity integer NOT NULL DEFAULT 1,
2024-12-24 14:29:04 +01:00
price double precision NOT NULL DEFAULT 0.00,
2022-12-25 23:21:27 +01:00
created_at timestamp without time zone NOT NULL DEFAULT now(),
updated_at timestamp without time zone,
PRIMARY KEY (id)
);
2024-12-24 14:29:04 +01:00
ALTER TABLE IF EXISTS "ordering".order_item
2022-12-25 23:21:27 +01:00
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 "ordering"."order"
OWNER to postgres;
ALTER TABLE IF EXISTS "ordering".order_item
OWNER to postgres;
-- TODO ^^ PRIVILEGES...