Skip to content

Commit feec365

Browse files
committed
chore: remove normalize funcs util methods
1 parent 53c9131 commit feec365

File tree

2 files changed

+3
-125
lines changed

2 files changed

+3
-125
lines changed

.scripts/compare-database.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ const omit = (object, ...keys) =>
88
const omitArray = (arrayOfObjects, ...keys) =>
99
arrayOfObjects.map((value) => omit(value, ...keys));
1010

11-
// Function to normalize function/trigger definitions by stripping whitespace from each line
12-
export const normalizeDefinition = (definition) => {
13-
if (typeof definition !== 'string') {
14-
return definition;
15-
}
16-
17-
return definition
18-
.split('\n')
19-
.map(line => line.trim())
20-
.join('\n');
21-
};
22-
2311
const schemas = ['cloud', 'public'];
2412
const schemasArray = `(${schemas.map((schema) => `'${schema}'`).join(', ')})`;
2513

@@ -172,18 +160,6 @@ const queryDatabaseManifest = async (database) => {
172160
return { policyname, ...rest };
173161
};
174162

175-
// Normalize function definitions by stripping whitespace from each line
176-
const normalizeFuncDefinition = ({ definition, ...rest }) => ({
177-
...rest,
178-
definition: normalizeDefinition(definition),
179-
});
180-
181-
// Normalize trigger action statements by stripping whitespace from each line
182-
const normalizeTriggerAction = ({ action_statement, ...rest }) => ({
183-
...rest,
184-
action_statement: normalizeDefinition(action_statement),
185-
});
186-
187163
// Omit generated ids and values
188164
return {
189165
tables: omitArray(tables, 'table_catalog'),
@@ -218,8 +194,8 @@ const queryDatabaseManifest = async (database) => {
218194
'conexclop'
219195
),
220196
indexes,
221-
funcs: funcs.map(normalizeFuncDefinition),
222-
triggers: omitArray(triggers, 'trigger_catalog', 'event_object_catalog').map(normalizeTriggerAction),
197+
funcs,
198+
triggers: omitArray(triggers, 'trigger_catalog', 'event_object_catalog'),
223199
policies: policies.map(normalizeRoles).map(normalizePolicyname),
224200
columnGrants: omitArray(columnGrants, 'table_catalog').map(
225201
normalizeGrantee

.scripts/compare-database.test.js

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import assert from 'node:assert';
11-
import { autoCompare, normalizeDefinition, buildSortByKeys, getValueComplexity } from './compare-database.js';
11+
import { autoCompare, buildSortByKeys, getValueComplexity } from './compare-database.js';
1212

1313
// Test helper function
1414
const runTest = (testName, testFn) => {
@@ -201,104 +201,6 @@ runTest('autoCompare - buildSortByKeys integration for database data', () => {
201201
assert.strictEqual(comparison, 0); // Should be identical
202202
});
203203

204-
// Test cases for normalizeDefinition function
205-
runTest('normalizeDefinition - single line without leading/trailing spaces', () => {
206-
const input = 'CREATE FUNCTION test() RETURNS void';
207-
const expected = 'CREATE FUNCTION test() RETURNS void';
208-
const result = normalizeDefinition(input);
209-
210-
assert.strictEqual(result, expected);
211-
});
212-
213-
runTest('normalizeDefinition - single line with leading/trailing spaces', () => {
214-
const input = ' CREATE FUNCTION test() RETURNS void ';
215-
const expected = 'CREATE FUNCTION test() RETURNS void';
216-
const result = normalizeDefinition(input);
217-
218-
assert.strictEqual(result, expected);
219-
});
220-
221-
runTest('normalizeDefinition - multi-line with various indentation', () => {
222-
const input = `CREATE OR REPLACE FUNCTION test_function()
223-
RETURNS trigger
224-
LANGUAGE plpgsql
225-
AS $function$
226-
BEGIN
227-
IF NEW.status IS NULL THEN
228-
NEW.status := 'active';
229-
END IF;
230-
RETURN NEW;
231-
END;
232-
$function$`;
233-
234-
const expected = `CREATE OR REPLACE FUNCTION test_function()
235-
RETURNS trigger
236-
LANGUAGE plpgsql
237-
AS $function$
238-
BEGIN
239-
IF NEW.status IS NULL THEN
240-
NEW.status := 'active';
241-
END IF;
242-
RETURN NEW;
243-
END;
244-
$function$`;
245-
246-
const result = normalizeDefinition(input);
247-
assert.strictEqual(result, expected);
248-
});
249-
250-
runTest('normalizeDefinition - trigger action statement', () => {
251-
const input = ` BEGIN
252-
UPDATE table1 SET updated_at = NOW() WHERE id = NEW.id;
253-
INSERT INTO audit_log (table_name, action) VALUES ('table1', 'UPDATE');
254-
RETURN NEW;
255-
END `;
256-
257-
const expected = `BEGIN
258-
UPDATE table1 SET updated_at = NOW() WHERE id = NEW.id;
259-
INSERT INTO audit_log (table_name, action) VALUES ('table1', 'UPDATE');
260-
RETURN NEW;
261-
END`;
262-
263-
const result = normalizeDefinition(input);
264-
assert.strictEqual(result, expected);
265-
});
266-
267-
runTest('normalizeDefinition - empty lines and mixed spacing', () => {
268-
const input = ` CREATE FUNCTION complex_func()
269-
270-
RETURNS TABLE(id integer, name text)
271-
AS $$
272-
SELECT id, name
273-
FROM users
274-
WHERE active = true;
275-
$$`;
276-
277-
const expected = `CREATE FUNCTION complex_func()
278-
279-
RETURNS TABLE(id integer, name text)
280-
AS $$
281-
SELECT id, name
282-
FROM users
283-
WHERE active = true;
284-
$$`;
285-
286-
const result = normalizeDefinition(input);
287-
assert.strictEqual(result, expected);
288-
});
289-
290-
runTest('normalizeDefinition - non-string input', () => {
291-
assert.strictEqual(normalizeDefinition(null), null);
292-
assert.strictEqual(normalizeDefinition(undefined), undefined);
293-
assert.strictEqual(normalizeDefinition(123), 123);
294-
assert.deepStrictEqual(normalizeDefinition({ key: 'value' }), { key: 'value' });
295-
});
296-
297-
runTest('normalizeDefinition - empty string', () => {
298-
assert.strictEqual(normalizeDefinition(''), '');
299-
assert.strictEqual(normalizeDefinition(' '), '');
300-
});
301-
302204
// Test cases for getValueComplexity function
303205
runTest('getValueComplexity - returns correct complexity scores', () => {
304206
assert.strictEqual(getValueComplexity(null), 0);

0 commit comments

Comments
 (0)