All checks were successful
CI / Test (1.24) (push) Successful in -26m21s
CI / Test (1.25) (push) Successful in -26m13s
CI / Build (push) Successful in -26m39s
CI / Lint (push) Successful in -26m29s
Release / Build and Release (push) Successful in -26m28s
Integration Tests / Integration Tests (push) Successful in -26m10s
* Introduce new templates for creating unique, check, and foreign key constraints with existence checks. * Add templates for setting sequence values and creating sequences. * Refactor existing SQL generation logic to utilize new templates for better maintainability and readability. * Ensure identifiers are properly quoted to handle special characters and reserved keywords.
19 lines
514 B
Cheetah
19 lines
514 B
Cheetah
DO $$
|
|
DECLARE
|
|
m_cnt bigint;
|
|
BEGIN
|
|
IF EXISTS (
|
|
SELECT 1 FROM pg_class c
|
|
INNER JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
WHERE c.relname = '{{.SequenceName}}'
|
|
AND n.nspname = '{{.SchemaName}}'
|
|
AND c.relkind = 'S'
|
|
) THEN
|
|
SELECT COALESCE(MAX({{quote_ident .ColumnName}}), 0) + 1
|
|
FROM {{quote_ident .SchemaName}}.{{quote_ident .TableName}}
|
|
INTO m_cnt;
|
|
|
|
PERFORM setval('{{quote_ident .SchemaName}}.{{quote_ident .SequenceName}}'::regclass, m_cnt);
|
|
END IF;
|
|
END;
|
|
$$; |