fix: replace regex constraint with LIKE '%/%' for PG compat

- constraint CHECK (value_cidr LIKE '%/%') instead of regex
- regex broke on managed PG with standard_conforming_strings=off
- ALTER TABLE adds constraint on existing tables
This commit is contained in:
2026-06-10 11:51:08 +04:00
parent 32cb0f4ac6
commit 02859d6a7a
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ipwhitelist", "name": "ipwhitelist",
"version": "0.5.35", "version": "0.5.36",
"description": "IP WhiteList microservice for cloud provider", "description": "IP WhiteList microservice for cloud provider",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
+8 -1
View File
@@ -35,7 +35,7 @@ async function ensureSchema() {
CREATE TABLE IF NOT EXISTS whitelist_entries ( CREATE TABLE IF NOT EXISTS whitelist_entries (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
company_id INTEGER NOT NULL REFERENCES companies(id) ON DELETE RESTRICT, company_id INTEGER NOT NULL REFERENCES companies(id) ON DELETE RESTRICT,
value_cidr VARCHAR(18) NOT NULL CHECK (value_cidr ~ '^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$'), value_cidr VARCHAR(18) NOT NULL CHECK (value_cidr LIKE '%/%'),
comment VARCHAR(255), comment VARCHAR(255),
created_by VARCHAR(255) NOT NULL, created_by VARCHAR(255) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
@@ -60,6 +60,13 @@ async function ensureSchema() {
); );
CREATE INDEX IF NOT EXISTS idx_audit_company_time ON audit_log(company_id, created_at DESC); CREATE INDEX IF NOT EXISTS idx_audit_company_time ON audit_log(company_id, created_at DESC);
`); `);
// Замена constraint на managed-совместимый (без regex, который ломается от standard_conforming_strings)
await pool.query(`
ALTER TABLE whitelist_entries DROP CONSTRAINT IF EXISTS whitelist_entries_value_cidr_check;
ALTER TABLE whitelist_entries ADD CONSTRAINT whitelist_entries_value_cidr_check CHECK (value_cidr LIKE '%/%');
`).catch(() => {}); // игнор если нет прав на ALTER
console.log('[db] Schema ensured'); console.log('[db] Schema ensured');
} }