Skip to content

Commit 8056c95

Browse files
committed
feat: single-file schema change example
1 parent 08927ea commit 8056c95

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

singlefile/schema.sql

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ $$;
7171
CREATE TABLE IF NOT EXISTS users (
7272
id integer PRIMARY KEY,
7373
email text NOT NULL CHECK (email LIKE '%@%'),
74-
name text NOT NULL
74+
name text NOT NULL,
75+
age integer CHECK (age >= 0)
7576
);
7677

7778
COMMENT ON TABLE users IS 'User accounts';
@@ -117,20 +118,13 @@ CREATE OR REPLACE TRIGGER users_update_trigger
117118
CREATE TABLE IF NOT EXISTS orders (
118119
id integer PRIMARY KEY,
119120
user_id integer NOT NULL REFERENCES users(id),
120-
status text DEFAULT 'pending' NOT NULL CHECK (status IN ('pending', 'completed')),
121-
amount numeric(10,2) DEFAULT 0.00
121+
status text DEFAULT 'pending' NOT NULL CHECK (status IN ('pending', 'completed'))
122122
);
123123

124124
COMMENT ON TABLE orders IS 'Customer orders';
125125

126126
COMMENT ON COLUMN orders.user_id IS 'Reference to user';
127127

128-
--
129-
-- Name: idx_orders_status; Type: INDEX; Schema: -; Owner: -
130-
--
131-
132-
CREATE INDEX IF NOT EXISTS idx_orders_status ON orders (status);
133-
134128
--
135129
-- Name: idx_orders_user_id; Type: INDEX; Schema: -; Owner: -
136130
--

0 commit comments

Comments
 (0)