Skip to content

Commit

Permalink
Merge pull request #75 from supabase/feat/remove-pg12-support
Browse files Browse the repository at this point in the history
feat: remove pg12 support
  • Loading branch information
soedirgo authored Jan 29, 2024
2 parents 6c9afe0 + b192ee1 commit aeedf40
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
pg-version: ['12', '13', '14', '15']
pg-version: ['13', '14', '15']

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
matrix:
extension_name:
- supautils
postgres: [12, 13, 14, 15]
postgres: [13, 14, 15]
box:
- { runner: ubuntu-20.04, arch: amd64 }
- { runner: arm-runner, arch: arm64 }
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ MODULE_big = supautils
OBJS = src/supautils.o src/privileged_extensions.o src/constrained_extensions.o src/utils.o

PG_VERSION = $(strip $(shell $(PG_CONFIG) --version | $(GREP) -oP '(?<=PostgreSQL )[0-9]+'))
PG_GE13 = $(shell test $(PG_VERSION) -ge 13; echo $$?)
SYSTEM = $(shell uname -s)

ifneq ($(SYSTEM), Linux)
TESTS = $(filter-out test/sql/ge13_%.sql, $(wildcard test/sql/*.sql))
else ifneq ($(PG_GE13), 0)
TESTS = $(filter-out test/sql/ge13_%.sql, $(wildcard test/sql/*.sql))
else
TESTS = $(wildcard test/sql/*.sql)
endif
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

<a href="https://github.com/supabase/supautils/actions"><img src="https://github.com/supabase/supautils/actions/workflows/main.yml/badge.svg" alt="Tests" height="18"></a>
<a href="https://github.com/olirice/alembic_utils/blob/master/LICENSE"><img src="https://img.shields.io/pypi/l/markdown-subtemplate.svg" alt="License" height="18"></a>
<a href=""><img src="https://img.shields.io/badge/postgresql-12+-blue.svg" alt="PostgreSQL version" height="18"></a>
<a href=""><img src="https://img.shields.io/badge/postgresql-13+-blue.svg" alt="PostgreSQL version" height="18"></a>

</p>

Supautils is an extension that secures a PostgreSQL cluster on a cloud environment.

It doesn't require creating database objects. It's a shared library that modifies PostgreSQL behavior through "hooks", not through tables or functions.

It's tested to work on PostgreSQL 12, 13, 14 and 15.
It's tested to work on PostgreSQL 13, 14 and 15.

## Installation

Expand Down Expand Up @@ -170,15 +170,12 @@ For testing the module locally, execute:
# might take a while in downloading all the dependencies
$ nix-shell

# test on pg 12
$ supautils-with-pg-12 make installcheck

# test on pg 13
$ supautils-with-pg-13 make installcheck

# test on pg 14
$ supautils-with-pg-14 make installcheck

# you can also test manually with
$ supautils-with-pg-12 psql -U rolecreator
$ supautils-with-pg-13 psql -U rolecreator
```
1 change: 0 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ with import (builtins.fetchTarball {
}) {};
let
supportedPgVersions = [
postgresql_12
postgresql_13
postgresql_14
postgresql_15
Expand Down
13 changes: 3 additions & 10 deletions src/constrained_extensions.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#include "utils.h"

#if PG13_GTE

#include <postgres.h>
#include <utils/json.h>
#include <utils/jsonb.h>
#include <utils/jsonfuncs.h>
#include <common/jsonapi.h>
#include <utils/memutils.h>
#include <miscadmin.h>
#include <tsearch/ts_locale.h>
#include <utils/builtins.h>
#include <utils/json.h>
#include <utils/jsonb.h>
#include <utils/jsonfuncs.h>
#include <utils/memutils.h>

#ifdef __linux__
Expand Down Expand Up @@ -240,5 +235,3 @@ void constrain_extension(
}
}
}

#endif
14 changes: 1 addition & 13 deletions src/supautils.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
#include <utils/snapmgr.h>
#include <utils/varlena.h>

#include "constrained_extensions.h"
#include "privileged_extensions.h"

#include "utils.h"

#if PG13_GTE
#include "constrained_extensions.h"
#endif

#define EREPORT_RESERVED_MEMBERSHIP(name) \
ereport(ERROR, \
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), \
Expand Down Expand Up @@ -61,14 +57,12 @@ static char *privileged_role = NULL;
static char *privileged_role_allowed_configs = NULL;
static ProcessUtility_hook_type prev_hook = NULL;

#if PG13_GTE
static char *constrained_extensions_str = NULL;
static constrained_extension cexts[MAX_CONSTRAINED_EXTENSIONS] = {0};
static size_t total_cexts = 0;

static void
constrained_extensions_assign_hook(const char *newval, void *extra);
#endif

void _PG_init(void);
void _PG_fini(void);
Expand Down Expand Up @@ -207,7 +201,6 @@ _PG_init(void)
NULL,
NULL);

#if PG13_GTE
DefineCustomStringVariable("supautils.constrained_extensions",
"Extensions that require a minimum amount of CPUs, memory and free disk to be installed",
NULL,
Expand All @@ -217,7 +210,6 @@ _PG_init(void)
NULL,
constrained_extensions_assign_hook,
NULL);
#endif

if(placeholders){
List* comma_separated_list;
Expand Down Expand Up @@ -551,11 +543,9 @@ supautils_hook(PROCESS_UTILITY_PARAMS)
case T_CreateExtensionStmt:
{

#if PG13_GTE
CreateExtensionStmt *stmt = (CreateExtensionStmt *)utility_stmt;

constrain_extension(stmt->extname, cexts, total_cexts);
#endif

handle_create_extension(prev_hook,
PROCESS_UTILITY_ARGS,
Expand Down Expand Up @@ -893,7 +883,6 @@ check_parameter(char *val, char *name)
}
}

#if PG13_GTE
void constrained_extensions_assign_hook(const char *newval, void *extra){
if (total_cexts > 0) {
for (size_t i = 0; i < total_cexts; i++){
Expand All @@ -911,7 +900,6 @@ void constrained_extensions_assign_hook(const char *newval, void *extra){
}
}
}
#endif

static void
confirm_reserved_roles(const char *target, bool allow_configurable_roles)
Expand Down
13 changes: 1 addition & 12 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <utils/acl.h>
#include <utils/queryenvironment.h>

#define PG13_GTE (PG_VERSION_NUM >= 130000)
#define PG14_GTE (PG_VERSION_NUM >= 140000)
#define PG15_GTE (PG_VERSION_NUM >= 150000)

Expand All @@ -25,7 +24,7 @@
#define PROCESS_UTILITY_ARGS \
pstmt, queryString, readOnlyTree, context, params, queryEnv, dest, qc

#elif PG13_GTE
#else // PG13

#define PROCESS_UTILITY_PARAMS \
PlannedStmt *pstmt, const char *queryString, \
Expand All @@ -34,16 +33,6 @@
#define PROCESS_UTILITY_ARGS \
pstmt, queryString, context, params, queryEnv, dest, qc

#else

#define PROCESS_UTILITY_PARAMS \
PlannedStmt *pstmt, const char *queryString, \
ProcessUtilityContext context, ParamListInfo params, \
QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag

#define PROCESS_UTILITY_ARGS \
pstmt, queryString, context, params, queryEnv, dest, completionTag

#endif

#define run_process_utility_hook(process_utility_hook) \
Expand Down

0 comments on commit aeedf40

Please sign in to comment.