Skip to content

Commit

Permalink
fix: allow space and no-space syntaxes for SQLite constraints (#9238)
Browse files Browse the repository at this point in the history
Closes #9237

Co-authored-by: Brice Miclo <brice.miclo@socomec.com>
  • Loading branch information
Obiwan1995 and Obiwan1995 committed Aug 24, 2022
1 parent 14dfadb commit bb07244
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts
Expand Up @@ -1497,15 +1497,15 @@ export abstract class AbstractSqliteQueryRunner
}),
)

// find unique constraints from CREATE TABLE sql
// find foreign key constraints from CREATE TABLE sql
let fkResult
const fkMappings: {
name: string
columns: string[]
referencedTableName: string
}[] = []
const fkRegex =
/CONSTRAINT "([^"]*)" FOREIGN KEY \((.*?)\) REFERENCES "([^"]*)" /g
/CONSTRAINT "([^"]*)" FOREIGN KEY ?\((.*?)\) REFERENCES "([^"]*)"/g
while ((fkResult = fkRegex.exec(sql)) !== null) {
fkMappings.push({
name: fkResult[1],
Expand Down Expand Up @@ -1561,7 +1561,7 @@ export abstract class AbstractSqliteQueryRunner
// find unique constraints from CREATE TABLE sql
let uniqueRegexResult
const uniqueMappings: { name: string; columns: string[] }[] = []
const uniqueRegex = /CONSTRAINT "([^"]*)" UNIQUE \((.*?)\)/g
const uniqueRegex = /CONSTRAINT "([^"]*)" UNIQUE ?\((.*?)\)/g
while ((uniqueRegexResult = uniqueRegex.exec(sql)) !== null) {
uniqueMappings.push({
name: uniqueRegexResult[1],
Expand Down Expand Up @@ -1625,7 +1625,8 @@ export abstract class AbstractSqliteQueryRunner

// build checks
let result
const regexp = /CONSTRAINT "([^"]*)" CHECK (\(.*?\))([,]|[)]$)/g
const regexp =
/CONSTRAINT "([^"]*)" CHECK ?(\(.*?\))([,]|[)]$)/g
while ((result = regexp.exec(sql)) !== null) {
table.checks.push(
new TableCheck({
Expand Down

0 comments on commit bb07244

Please sign in to comment.