Create UDF which returns the currently running version

pull/903/merge^2
Brian Cloutier 2016-10-24 17:32:40 +03:00
parent 1e6d1ef67e
commit 21b3090fec
4 changed files with 66 additions and 2 deletions

View File

@ -8,7 +8,21 @@ EXTENSION = citus
EXTVERSIONS = 5.0 5.0-1 5.0-2 \
5.1-1 5.1-2 5.1-3 5.1-4 5.1-5 5.1-6 5.1-7 5.1-8 \
5.2-1 5.2-2 5.2-3 5.2-4 \
6.0-1 6.0-2 6.0-3 6.0-4 6.0-5 6.0-6 6.0-7 6.0-8 6.0-9 6.0-10 6.0-11 6.0-12 6.0-13 6.0-14 6.0-15
6.0-1 6.0-2 6.0-3 6.0-4 6.0-5 6.0-6 6.0-7 6.0-8 6.0-9 6.0-10 6.0-11 6.0-12 \
6.0-13 6.0-14 6.0-15 6.0-16
ifeq ($(wildcard citus.control),)
$(error citus.control not found!)
endif
MODVERSION = $(shell grep "default_version" citus.control | grep -oE "'[0-9]+\.[0-9]+-[0-9]+'")
ifeq ($(MODVERSION),)
WRONGVERSION = $(shell grep "default_version" citus.control | grep -oE "'.*'")
$(warning version $(WRONGVERSION) is incorrect)
$(error the version in citus.control should match: \d+.\d+-\d+)
endif
CITUS_VERSION = $(shell echo $(MODVERSION) | sed "s/\'//")
$(info building citus version $(CITUS_VERSION))
override CFLAGS+=-DCITUS_VERSION=$(CITUS_VERSION)
# All citus--*.sql files in the source directory
DATA = $(patsubst $(citus_abs_srcdir)/%.sql,%.sql,$(wildcard $(citus_abs_srcdir)/$(EXTENSION)--*--*.sql))
@ -88,6 +102,8 @@ $(EXTENSION)--6.0-14.sql: $(EXTENSION)--6.0-13.sql $(EXTENSION)--6.0-13--6.0-14.
cat $^ > $@
$(EXTENSION)--6.0-15.sql: $(EXTENSION)--6.0-14.sql $(EXTENSION)--6.0-14--6.0-15.sql
cat $^ > $@
$(EXTENSION)--6.0-16.sql: $(EXTENSION)--6.0-15.sql $(EXTENSION)--6.0-15--6.0-16.sql
cat $^ > $@
NO_PGXS = 1

View File

@ -0,0 +1,8 @@
/* citus--6.0-9--6.0-10.sql */
CREATE FUNCTION citus_running_version()
RETURNS text
LANGUAGE C IMMUTABLE
AS 'MODULE_PATHNAME', $$citus_running_version$$;
COMMENT ON FUNCTION citus_running_version()
IS 'Get the version of the loaded citus module';

View File

@ -1,6 +1,6 @@
# Citus extension
comment = 'Citus distributed database'
default_version = '6.0-15'
default_version = '6.0-16'
module_pathname = '$libdir/citus'
relocatable = false
schema = pg_catalog

View File

@ -0,0 +1,40 @@
/*-------------------------------------------------------------------------
*
* create_distributed_relation.c
* Routines relation to the creation of distributed relations.
*
* Copyright (c) 2012-2016, Citus Data, Inc.
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "lib/stringinfo.h"
#include "utils/builtins.h"
/* exports for SQL callable functions */
PG_FUNCTION_INFO_V1(citus_running_version);
#if !defined(CITUS_VERSION)
#error Something went wrong, CITUS_VERSION is not set!
#endif
#define STRINGIFY(x) #x
#define MACRO(x) STRINGIFY(x)
/*
* citus_running_version returns the version string the currently running code was built
* with.
*/
Datum
citus_running_version(PG_FUNCTION_ARGS)
{
const char *versionStr = MACRO(CITUS_VERSION);
text *versionText = cstring_to_text(versionStr);
PG_RETURN_TEXT_P(versionText);
}