Skip to content

Commit c02c8fa

Browse files
committed
Merge branch 'fix/asts'
* fix/asts: updates more locations migration works stuff dbe inflection ext migrations migrations migrations wip
2 parents 376f5a4 + 05d9d1c commit c02c8fa

File tree

5 files changed

+757
-1
lines changed

5 files changed

+757
-1
lines changed

docker-compose.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "2"
1+
version: "3"
22
services:
33
postgres:
44
container_name: launchql-postgres
@@ -14,3 +14,11 @@ services:
1414
- ./bin:/sql-bin
1515
- ./extensions:/sql-extensions
1616
- ./packages:/sql-packages
17+
deploy:
18+
resources:
19+
limits:
20+
cpus: '2'
21+
memory: 8G
22+
reservations:
23+
cpus: '2'
24+
memory: 8G

packages/ast/deploy/schemas/ast_helpers/procedures/helpers.sql

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,97 @@ $$
11611161
LANGUAGE 'plpgsql'
11621162
IMMUTABLE;
11631163

1164+
CREATE FUNCTION ast_helpers.column_type_identifier (
1165+
v_column_name text,
1166+
v_column_type text,
1167+
v_is_array bool
1168+
)
1169+
RETURNS jsonb
1170+
AS $$
1171+
DECLARE
1172+
ast jsonb;
1173+
BEGIN
1174+
IF (v_is_array IS TRUE) THEN
1175+
ast = ast.type_name(
1176+
v_names := to_jsonb(ARRAY[
1177+
-- ast.string('pg_catalog'),
1178+
ast.string(v_column_type)
1179+
]),
1180+
v_arrayBounds := to_jsonb(ARRAY[
1181+
ast.integer(-1)
1182+
])
1183+
);
1184+
ELSE
1185+
ast = ast.type_name(
1186+
v_names := to_jsonb(ARRAY[
1187+
-- ast.string('pg_catalog'),
1188+
ast.string(v_column_type)
1189+
])
1190+
);
1191+
END IF;
1192+
RETURN ast;
1193+
END;
1194+
$$
1195+
LANGUAGE 'plpgsql'
1196+
IMMUTABLE;
1197+
1198+
CREATE FUNCTION ast_helpers.column_geotype_identifier (
1199+
v_column_geo_type text,
1200+
v_column_geo_num int DEFAULT 4326
1201+
)
1202+
RETURNS jsonb
1203+
AS $$
1204+
DECLARE
1205+
ast jsonb;
1206+
BEGIN
1207+
RETURN ast.type_name(
1208+
v_names := to_jsonb(ARRAY[
1209+
ast.string('geometry')
1210+
]),
1211+
v_typmods := to_jsonb(ARRAY[
1212+
ast.column_ref(
1213+
v_fields := to_jsonb(ARRAY[
1214+
ast.string(v_column_geo_type)
1215+
])
1216+
),
1217+
ast.a_const( ast.integer(v_column_geo_num) )
1218+
]),
1219+
v_typemod := -1
1220+
);
1221+
END;
1222+
$$
1223+
LANGUAGE 'plpgsql'
1224+
IMMUTABLE;
1225+
1226+
CREATE FUNCTION ast_helpers.alter_table_add_column (
1227+
v_schema_name text,
1228+
v_table_name text,
1229+
v_column_name text,
1230+
v_column_type text,
1231+
v_is_array bool
1232+
)
1233+
RETURNS jsonb
1234+
AS $$
1235+
DECLARE
1236+
ast jsonb;
1237+
BEGIN
1238+
ast = ast_helpers.column_type_identifier(
1239+
v_column_name := v_column_name,
1240+
v_column_type := v_column_type,
1241+
v_is_array := v_is_array
1242+
);
1243+
1244+
RETURN ast_helpers.alter_table_add_column(
1245+
v_schema_name := v_schema_name,
1246+
v_table_name := v_table_name,
1247+
v_column_name := v_column_name,
1248+
v_column_type := ast
1249+
);
1250+
END;
1251+
$$
1252+
LANGUAGE 'plpgsql'
1253+
IMMUTABLE;
1254+
11641255
-- for control over more complex types, use this
11651256
CREATE FUNCTION ast_helpers.alter_table_add_column (
11661257
v_schema_name text,

packages/ast/sql/ast--0.0.1.sql

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,6 +3826,72 @@ BEGIN
38263826
END;
38273827
$EOFCODE$ LANGUAGE plpgsql IMMUTABLE;
38283828

3829+
CREATE FUNCTION ast_helpers.column_type_identifier ( v_column_name text, v_column_type text, v_is_array bool ) RETURNS jsonb AS $EOFCODE$
3830+
DECLARE
3831+
ast jsonb;
3832+
BEGIN
3833+
IF (v_is_array IS TRUE) THEN
3834+
ast = ast.type_name(
3835+
v_names := to_jsonb(ARRAY[
3836+
-- ast.string('pg_catalog'),
3837+
ast.string(v_column_type)
3838+
]),
3839+
v_arrayBounds := to_jsonb(ARRAY[
3840+
ast.integer(-1)
3841+
])
3842+
);
3843+
ELSE
3844+
ast = ast.type_name(
3845+
v_names := to_jsonb(ARRAY[
3846+
-- ast.string('pg_catalog'),
3847+
ast.string(v_column_type)
3848+
])
3849+
);
3850+
END IF;
3851+
RETURN ast;
3852+
END;
3853+
$EOFCODE$ LANGUAGE plpgsql IMMUTABLE;
3854+
3855+
CREATE FUNCTION ast_helpers.column_geotype_identifier ( v_column_geo_type text, v_column_geo_num int DEFAULT 4326 ) RETURNS jsonb AS $EOFCODE$
3856+
DECLARE
3857+
ast jsonb;
3858+
BEGIN
3859+
RETURN ast.type_name(
3860+
v_names := to_jsonb(ARRAY[
3861+
ast.string('geometry')
3862+
]),
3863+
v_typmods := to_jsonb(ARRAY[
3864+
ast.column_ref(
3865+
v_fields := to_jsonb(ARRAY[
3866+
ast.string(v_column_geo_type)
3867+
])
3868+
),
3869+
ast.a_const( ast.integer(v_column_geo_num) )
3870+
]),
3871+
v_typemod := -1
3872+
);
3873+
END;
3874+
$EOFCODE$ LANGUAGE plpgsql IMMUTABLE;
3875+
3876+
CREATE FUNCTION ast_helpers.alter_table_add_column ( v_schema_name text, v_table_name text, v_column_name text, v_column_type text, v_is_array bool ) RETURNS jsonb AS $EOFCODE$
3877+
DECLARE
3878+
ast jsonb;
3879+
BEGIN
3880+
ast = ast_helpers.column_type_identifier(
3881+
v_column_name := v_column_name,
3882+
v_column_type := v_column_type,
3883+
v_is_array := v_is_array
3884+
);
3885+
3886+
RETURN ast_helpers.alter_table_add_column(
3887+
v_schema_name := v_schema_name,
3888+
v_table_name := v_table_name,
3889+
v_column_name := v_column_name,
3890+
v_column_type := ast
3891+
);
3892+
END;
3893+
$EOFCODE$ LANGUAGE plpgsql IMMUTABLE;
3894+
38293895
CREATE FUNCTION ast_helpers.alter_table_add_column ( v_schema_name text, v_table_name text, v_column_name text, v_column_type jsonb ) RETURNS jsonb AS $EOFCODE$
38303896
DECLARE
38313897
ast jsonb;

0 commit comments

Comments
 (0)