Normally each module is tested in aq database named contrib_regression,
which is dropped and recreated at the beginhning of each pg_regress run.
This mode, enabled by adding USE_MODULE_DB=1 to the make command line,
runs most modules in a database with the module name embedded in it.
This will make testing pg_upgrade on clusters with the contrib modules
a lot easier.
Still to be done: adapt to the MSVC build system.
Backpatch to 9.0, which is the earliest version it is reasonably
possible to test upgrading from.
 
 REGRESS = dblink
 
+# the db name is hard-coded in the tests
+override undefine USE_MODULE_DB
+
 ifdef USE_PGXS
 PG_CONFIG = pg_config
 PGXS := $(shell $(PG_CONFIG) --pgxs)
 
 
 PL_TESTDB = pl_regression
 CONTRIB_TESTDB = contrib_regression
+ifneq ($(MODULE_big),)
+  CONTRIB_TESTDB_MODULE = contrib_regression_$(MODULE_big)
+else 
+  ifneq ($(MODULES),)
+    CONTRIB_TESTDB_MODULE = contrib_regression_$(MODULES)
+  else
+    CONTRIB_TESTDB_MODULE = contrib_regression
+  endif
+endif
 
 ifdef NO_LOCALE
 NOLOCALE += --no-locale
 
 ifdef REGRESS
 
 # Select database to use for running the tests
-REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
+ifdef USE_MODULE_DB
+  REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE)
+else
+  REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
+endif
 
 # where to find psql for running the tests
 PSQLDIR = $(bindir)