-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: extensions parameter overrides #76
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ lib, stdenv, fetchFromGitHub, postgresql }: | ||
|
||
stdenv.mkDerivation rec { | ||
pname = "pg_cron"; | ||
version = "1.5.2"; | ||
|
||
buildInputs = [ postgresql ]; | ||
|
||
src = fetchFromGitHub { | ||
owner = "citusdata"; | ||
repo = pname; | ||
rev = "v${version}"; | ||
hash = "sha256-+quVWbKJy6wXpL/zwTk5FF7sYwHA7I97WhWmPO/HSZ4="; | ||
}; | ||
|
||
installPhase = '' | ||
mkdir -p $out/{lib,share/postgresql/extension} | ||
|
||
cp *.so $out/lib | ||
cp *.sql $out/share/postgresql/extension | ||
cp *.control $out/share/postgresql/extension | ||
''; | ||
|
||
meta = with lib; { | ||
description = "Run Cron jobs through PostgreSQL"; | ||
homepage = "https://github.com/citusdata/pg_cron"; | ||
changelog = "https://github.com/citusdata/pg_cron/raw/v${version}/CHANGELOG.md"; | ||
maintainers = with maintainers; [ thoughtpolice ]; | ||
platforms = postgresql.meta.platforms; | ||
license = licenses.postgresql; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#include <postgres.h> | ||
|
||
#include <common/jsonapi.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> | ||
|
||
#include "extensions_parameter_overrides.h" | ||
|
||
static void json_array_start(void *state) { | ||
json_extension_parameter_overrides_parse_state *parse = state; | ||
|
||
parse->state = JEPO_UNEXPECTED_ARRAY; | ||
parse->error_msg = "unexpected array"; | ||
} | ||
|
||
static void json_object_start(void *state) { | ||
json_extension_parameter_overrides_parse_state *parse = state; | ||
|
||
switch (parse->state) { | ||
case JEPO_EXPECT_TOPLEVEL_START: | ||
parse->state = JEPO_EXPECT_TOPLEVEL_FIELD; | ||
break; | ||
case JEPO_EXPECT_SCHEMA: | ||
parse->error_msg = "unexpected object for schema, expected a value"; | ||
parse->state = JEPO_UNEXPECTED_OBJECT; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
static void json_object_end(void *state) { | ||
json_extension_parameter_overrides_parse_state *parse = state; | ||
|
||
switch (parse->state) { | ||
case JEPO_EXPECT_PARAMETER_OVERRIDES_START: | ||
parse->state = JEPO_EXPECT_TOPLEVEL_FIELD; | ||
(parse->total_epos)++; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
static void json_object_field_start(void *state, char *fname, bool isnull) { | ||
json_extension_parameter_overrides_parse_state *parse = state; | ||
extension_parameter_overrides *x = &parse->epos[parse->total_epos]; | ||
|
||
switch (parse->state) { | ||
case JEPO_EXPECT_TOPLEVEL_FIELD: | ||
x->name = MemoryContextStrdup(TopMemoryContext, fname); | ||
parse->state = JEPO_EXPECT_PARAMETER_OVERRIDES_START; | ||
break; | ||
|
||
case JEPO_EXPECT_PARAMETER_OVERRIDES_START: | ||
if (strcmp(fname, "schema") == 0) | ||
parse->state = JEPO_EXPECT_SCHEMA; | ||
else { | ||
parse->state = JEPO_UNEXPECTED_FIELD; | ||
parse->error_msg = "unexpected field, only schema is allowed"; | ||
} | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
static void json_scalar(void *state, char *token, JsonTokenType tokentype) { | ||
json_extension_parameter_overrides_parse_state *parse = state; | ||
extension_parameter_overrides *x = &parse->epos[parse->total_epos]; | ||
|
||
switch (parse->state) { | ||
case JEPO_EXPECT_SCHEMA: | ||
if (tokentype == JSON_TOKEN_STRING) { | ||
x->schema = MemoryContextStrdup(TopMemoryContext, token); | ||
parse->state = JEPO_EXPECT_PARAMETER_OVERRIDES_START; | ||
} else { | ||
parse->state = JEPO_UNEXPECTED_SCHEMA_VALUE; | ||
parse->error_msg = "unexpected schema value, expected a string"; | ||
} | ||
break; | ||
|
||
case JEPO_EXPECT_TOPLEVEL_START: | ||
parse->state = JEPO_UNEXPECTED_SCALAR; | ||
parse->error_msg = "unexpected scalar, expected an object"; | ||
break; | ||
|
||
case JEPO_EXPECT_PARAMETER_OVERRIDES_START: | ||
parse->state = JEPO_UNEXPECTED_SCALAR; | ||
parse->error_msg = "unexpected scalar, expected an object"; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
json_extension_parameter_overrides_parse_state | ||
parse_extensions_parameter_overrides(const char *str, | ||
extension_parameter_overrides *epos) { | ||
JsonLexContext *lex; | ||
JsonParseErrorType json_error; | ||
JsonSemAction sem; | ||
|
||
json_extension_parameter_overrides_parse_state state = { | ||
JEPO_EXPECT_TOPLEVEL_START, NULL, 0, epos}; | ||
|
||
lex = | ||
makeJsonLexContextCstringLen(pstrdup(str), strlen(str), PG_UTF8, true); | ||
|
||
sem.semstate = &state; | ||
sem.object_start = json_object_start; | ||
sem.object_end = json_object_end; | ||
sem.array_start = json_array_start; | ||
sem.array_end = NULL; | ||
sem.object_field_start = json_object_field_start; | ||
sem.object_field_end = NULL; | ||
sem.array_element_start = NULL; | ||
sem.array_element_end = NULL; | ||
sem.scalar = json_scalar; | ||
|
||
json_error = pg_parse_json(lex, &sem); | ||
|
||
if (json_error != JSON_SUCCESS) | ||
state.error_msg = "invalid json"; | ||
|
||
return state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef EXTENSIONS_PARAMETER_OVERRIDES_H | ||
#define EXTENSIONS_PARAMETER_OVERRIDES_H | ||
|
||
#include <postgres.h> | ||
|
||
typedef struct { | ||
char *name; | ||
char *schema; | ||
} extension_parameter_overrides; | ||
|
||
typedef enum { | ||
JEPO_EXPECT_TOPLEVEL_START, | ||
JEPO_EXPECT_TOPLEVEL_FIELD, | ||
JEPO_EXPECT_PARAMETER_OVERRIDES_START, | ||
JEPO_EXPECT_SCHEMA, | ||
JEPO_UNEXPECTED_FIELD, | ||
JEPO_UNEXPECTED_ARRAY, | ||
JEPO_UNEXPECTED_SCALAR, | ||
JEPO_UNEXPECTED_OBJECT, | ||
JEPO_UNEXPECTED_SCHEMA_VALUE | ||
} json_extension_parameter_overrides_semantic_state; | ||
|
||
typedef struct { | ||
json_extension_parameter_overrides_semantic_state state; | ||
char *error_msg; | ||
int total_epos; | ||
extension_parameter_overrides *epos; | ||
} json_extension_parameter_overrides_parse_state; | ||
|
||
extern json_extension_parameter_overrides_parse_state | ||
parse_extensions_parameter_overrides(const char *str, | ||
extension_parameter_overrides *epos); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest pg_cron nixpkg (1.6.2) breaks on PG14, so we pin the version on 1.5.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pinned pg_cron breaks on pg 16 though. I'll change the test to use a contrib extension to avoid these issues.