Skip to content

Commit 3f10237

Browse files
test: add reproduction test for issue #4000 - large INSERT INTO statements
Add test case that reproduces the 'syntax error at end of input' bug when parsing large structure.sql files with very long INSERT INTO schema_migrations statements (3000+ entries). This test currently fails with the expected error, confirming the bug reproduction. Refs: #4000 Co-Authored-By: hirotaka.miyagi@route06.co.jp <h.miyagi.cnw@gmail.com>
1 parent 95db078 commit 3f10237

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

frontend/packages/schema/src/parser/sql/postgresql/index.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,4 +1230,48 @@ CREATE TYPE status AS ENUM ('active', 'inactive');
12301230
})
12311231
})
12321232
})
1233+
1234+
describe('issue #4000: large INSERT INTO statements', () => {
1235+
it('should handle very long INSERT INTO schema_migrations statements', async () => {
1236+
const migrationCount = 3000
1237+
const migrationValues = []
1238+
for (let i = 1; i <= migrationCount; i++) {
1239+
migrationValues.push(`('migration_${i}')`)
1240+
}
1241+
1242+
const sql = /* sql */ `
1243+
-- Dummy PostgreSQL structure.sql for reproduction
1244+
CREATE EXTENSION IF NOT EXISTS "plpgsql" WITH SCHEMA pg_catalog;
1245+
1246+
CREATE TABLE public.users (
1247+
id SERIAL PRIMARY KEY,
1248+
name VARCHAR(255),
1249+
email VARCHAR(255)
1250+
);
1251+
1252+
CREATE TABLE public.posts (
1253+
id SERIAL PRIMARY KEY,
1254+
user_id INTEGER REFERENCES public.users(id),
1255+
title VARCHAR(255),
1256+
body TEXT
1257+
);
1258+
1259+
-- Insert migrations
1260+
INSERT INTO schema_migrations VALUES
1261+
${migrationValues.join(',\n')};
1262+
`
1263+
1264+
const { value, errors } = await processor(sql)
1265+
1266+
expect(errors).toEqual([])
1267+
1268+
// Verify that the tables were parsed correctly
1269+
expect(value.tables).toHaveProperty('users')
1270+
expect(value.tables).toHaveProperty('posts')
1271+
expect(value.tables['users']?.columns).toHaveProperty('id')
1272+
expect(value.tables['users']?.columns).toHaveProperty('name')
1273+
expect(value.tables['users']?.columns).toHaveProperty('email')
1274+
expect(value.tables['posts']?.columns).toHaveProperty('user_id')
1275+
})
1276+
})
12331277
})

0 commit comments

Comments
 (0)