Skip to content

Commit f094795

Browse files
committed
Clean up tests and fix regression
It was possible to specify both --schema and --table which probably -should- be legal but would need some code to be rewritten. This patch adds a check that both can't be specified and returns an error telling the user to use schema.table notation instead. A regression test checking this behaviour was added.
1 parent 9b381f5 commit f094795

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

bin/pg_repack.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ main(int argc, char *argv[])
305305
}
306306
else
307307
{
308+
if (schema_list.head && table_list.head)
309+
ereport(ERROR,
310+
(errcode(EINVAL),
311+
errmsg("cannot repack specific table(s) in schema, use schema.table notation instead")));
312+
308313
if (noorder)
309314
orderby = "";
310315

regress/expected/repack.out

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,22 +353,27 @@ CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtes
353353
\! pg_repack --dbname=contrib_regression --table=trg4
354354
INFO: repacking table "trg4"
355355
--
356-
-- Repack single schema
356+
-- Test --schema
357357
--
358358
CREATE SCHEMA test_schema1;
359359
CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY);
360360
CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY);
361-
\! pg_repack --dbname=contrib_regression --schema=test_schema1
362-
INFO: repacking table "test_schema1.tbl1"
363-
INFO: repacking table "test_schema1.tbl2"
364-
--
365-
-- Repack two schemas
366-
--
367361
CREATE SCHEMA test_schema2;
368362
CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY);
369363
CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY);
370-
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2
371-
INFO: repacking table "test_schema2.tbl1"
364+
-- => OK
365+
\! pg_repack --dbname=contrib_regression --schema=test_schema1
372366
INFO: repacking table "test_schema1.tbl1"
373367
INFO: repacking table "test_schema1.tbl2"
368+
-- => OK
369+
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2
370+
INFO: repacking table "test_schema2.tbl1"
374371
INFO: repacking table "test_schema2.tbl2"
372+
INFO: repacking table "test_schema1.tbl2"
373+
INFO: repacking table "test_schema1.tbl1"
374+
-- => ERROR
375+
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1
376+
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead
377+
-- => ERROR
378+
\! pg_repack --dbname=contrib_regression --all --schema=test_schema1
379+
ERROR: cannot repack specific schema(s) in all databases

regress/sql/repack.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,19 @@ CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtes
208208
\! pg_repack --dbname=contrib_regression --table=trg4
209209

210210
--
211-
-- Repack single schema
211+
-- Test --schema
212212
--
213213
CREATE SCHEMA test_schema1;
214214
CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY);
215215
CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY);
216-
\! pg_repack --dbname=contrib_regression --schema=test_schema1
217-
218-
--
219-
-- Repack two schemas
220-
--
221216
CREATE SCHEMA test_schema2;
222217
CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY);
223218
CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY);
219+
-- => OK
220+
\! pg_repack --dbname=contrib_regression --schema=test_schema1
221+
-- => OK
224222
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2
223+
-- => ERROR
224+
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1
225+
-- => ERROR
226+
\! pg_repack --dbname=contrib_regression --all --schema=test_schema1

0 commit comments

Comments
 (0)