From 25f919576fb29681fc6fb5ad5c2df8b06004a40d Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Tue, 12 Apr 2016 15:03:19 -0700 Subject: [PATCH] Add very basic infrastructure for schema upgrade scripts. Citus' extension version now has a -$schemaversion appendix. When the schema is changed, a new schema version has to be added; changes to the same schema version several commits inside a single pull request are ok. Schema migration scripts between each schema version have to be added. To ensure upgrade scripts work correctly a new regression test ensures that all steps work. The extension scripts to-be-used for CREATE EXTENSION (i.e. not extension updates) are generated by concatenating citus.sql and the relevant migration scripts. --- src/backend/distributed/Makefile | 14 +++++++++---- src/backend/distributed/citus--5.0--5.0-1.sql | 3 +++ src/backend/distributed/citus.control | 2 +- src/test/regress/expected/multi_extension.out | 17 ++++++++++++++++ src/test/regress/multi_schedule | 1 + src/test/regress/sql/multi_extension.sql | 20 +++++++++++++++++++ 6 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/backend/distributed/citus--5.0--5.0-1.sql create mode 100644 src/test/regress/expected/multi_extension.out create mode 100644 src/test/regress/sql/multi_extension.sql diff --git a/src/backend/distributed/Makefile b/src/backend/distributed/Makefile index 039d1e8b4..fd9b920e9 100644 --- a/src/backend/distributed/Makefile +++ b/src/backend/distributed/Makefile @@ -5,8 +5,11 @@ citus_top_builddir = ../../.. MODULE_big = citus EXTENSION = citus -EXTVERSION = 5.0 -DATA_built = $(EXTENSION)--$(EXTVERSION).sql +EXTVERSIONS = 5.0 5.0-1 +# All citus--*.sql files in the source directory +DATA = $(patsubst $(citus_abs_srcdir)/%.sql,%.sql,$(wildcard $(citus_abs_srcdir)/$(EXTENSION)--*--*.sql)) +# Generated files for each version +DATA_built = $(foreach v,$(EXTVERSIONS),$(EXTENSION)--$(v).sql) SCRIPTS = ../../bin/scripts/copy_to_distributed_table # directories with source files @@ -20,8 +23,11 @@ OBJS += \ # be explicit about the default target all: -# define build process for latest install file -$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION).sql +# generate each version's file installation file by concatenating +# previous upgrade scripts +$(EXTENSION)--5.0.sql: $(EXTENSION).sql + cat $^ > $@ +$(EXTENSION)--5.0-1.sql: $(EXTENSION)--5.0.sql $(EXTENSION)--5.0--5.0-1.sql cat $^ > $@ NO_PGXS = 1 diff --git a/src/backend/distributed/citus--5.0--5.0-1.sql b/src/backend/distributed/citus--5.0--5.0-1.sql new file mode 100644 index 000000000..8c9e7938d --- /dev/null +++ b/src/backend/distributed/citus--5.0--5.0-1.sql @@ -0,0 +1,3 @@ +/* citus--5.0--5.0-1.sql */ + +-- Currently nothing to do here diff --git a/src/backend/distributed/citus.control b/src/backend/distributed/citus.control index 0f25b1dd7..7db6e73fd 100644 --- a/src/backend/distributed/citus.control +++ b/src/backend/distributed/citus.control @@ -1,6 +1,6 @@ # Citus extension comment = 'Citus distributed database' -default_version = '5.0' +default_version = '5.0-1' module_pathname = '$libdir/citus' relocatable = false schema = pg_catalog diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out new file mode 100644 index 000000000..6175881af --- /dev/null +++ b/src/test/regress/expected/multi_extension.out @@ -0,0 +1,17 @@ +-- +-- MULTI_EXTENSION +-- +-- Tests around extension creation / upgrades +-- +-- It'd be nice to script generation of this file, but alas, that's +-- not done yet. +-- DROP EXTENSION pre-created by the regression suite +DROP EXTENSION citus; +\c +-- Create extension in oldest version, test every upgrade step +CREATE EXTENSION citus VERSION '5.0'; +ALTER EXTENSION citus UPDATE TO '5.0-1'; +-- drop extension an re-create in newest version +DROP EXTENSION citus; +\c +CREATE EXTENSION citus; diff --git a/src/test/regress/multi_schedule b/src/test/regress/multi_schedule index 751243b5a..546d69b11 100644 --- a/src/test/regress/multi_schedule +++ b/src/test/regress/multi_schedule @@ -11,6 +11,7 @@ # --- # Tests around schema changes, these are run first, so there's no preexisting objects. # --- +test: multi_extension test: multi_table_ddl # ---------- diff --git a/src/test/regress/sql/multi_extension.sql b/src/test/regress/sql/multi_extension.sql new file mode 100644 index 000000000..7c851e1e1 --- /dev/null +++ b/src/test/regress/sql/multi_extension.sql @@ -0,0 +1,20 @@ +-- +-- MULTI_EXTENSION +-- +-- Tests around extension creation / upgrades +-- +-- It'd be nice to script generation of this file, but alas, that's +-- not done yet. + +-- DROP EXTENSION pre-created by the regression suite +DROP EXTENSION citus; +\c + +-- Create extension in oldest version, test every upgrade step +CREATE EXTENSION citus VERSION '5.0'; +ALTER EXTENSION citus UPDATE TO '5.0-1'; + +-- drop extension an re-create in newest version +DROP EXTENSION citus; +\c +CREATE EXTENSION citus;