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.
pull/471/head
Andres Freund 2016-04-12 15:03:19 -07:00
parent 5ffce3393a
commit 25f919576f
6 changed files with 52 additions and 5 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
/* citus--5.0--5.0-1.sql */
-- Currently nothing to do here

View File

@ -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

View File

@ -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;

View File

@ -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
# ----------

View File

@ -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;