(index: IndexDef, table: DatabaseTable, createPrimary = false)
| 1016 | } |
| 1017 | |
| 1018 | override createIndex(index: IndexDef, table: DatabaseTable, createPrimary = false): string { |
| 1019 | if (index.primary) { |
| 1020 | return ''; |
| 1021 | } |
| 1022 | |
| 1023 | if (index.expression) { |
| 1024 | return index.expression; |
| 1025 | } |
| 1026 | |
| 1027 | const needsAutoNotNull = index.unique && index.columnNames.some(column => table.getColumn(column)?.nullable); |
| 1028 | |
| 1029 | if (!needsAutoNotNull) { |
| 1030 | return this.getCreateIndexSQL(table.getShortestName(), index); |
| 1031 | } |
| 1032 | |
| 1033 | // Strip `index.where` from the base SQL so we can combine it with the auto NOT-NULL guard |
| 1034 | // ourselves, wrapping the user predicate in parens to defuse operator precedence |
| 1035 | // (a bare `a = 1 or b = 2 and [col] is not null` would bind as `a = 1 or (b = 2 and …)`). |
| 1036 | let sql = this.getCreateIndexSQL(table.getShortestName(), { ...index, where: undefined, disabled: false }); |
| 1037 | const autoNotNull = index.columnNames.map(c => `${this.quote(c)} is not null`).join(' and '); |
| 1038 | sql += index.where ? ` where (${index.where}) and ${autoNotNull}` : ` where ${autoNotNull}`; |
| 1039 | |
| 1040 | if (index.disabled) { |
| 1041 | sql += `;\nalter index ${this.quote(index.keyName)} on ${table.getQuotedName()} disable`; |
| 1042 | } |
| 1043 | |
| 1044 | return sql; |
| 1045 | } |
| 1046 | |
| 1047 | override dropForeignKey(tableName: string, constraintName: string): string { |
| 1048 | return `alter table ${this.quote(tableName)} drop constraint ${this.quote(constraintName)}`; |
no test coverage detected