Skip to content

Commit

Permalink
validate schema changes before application.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Jan 30, 2024
1 parent b8f7cf6 commit eba6e87
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/supabase-todolist
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
await this.bucketStorageAdapter.init();
const version = await this.options.database.execute('SELECT powersync_rs_version()');
this.sdkVersion = version.rows?.item(0)['powersync_rs_version()'] ?? '';
await this.updateSchema(this.options.schema);
this.ready = true;
this.iterateListeners((cb) => cb.initialized?.());
}
Expand Down
1 change: 1 addition & 0 deletions packages/powersync-sdk-common/src/db/schema/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class Schema {
}

toJSON() {
this.validate();
return {
tables: this.tables.map((t) => t.toJSON())
};
Expand Down
15 changes: 8 additions & 7 deletions packages/powersync-sdk-common/src/db/schema/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ export class Table {

const columnNames = new Set<string>();
columnNames.add('id');
for (const column in this.columns) {
if (column == 'id') {
for (const column of this.columns) {
const { name: columnName } = column;
if (column.name == 'id') {
throw new Error(`${this.name}: id column is automatically added, custom id columns are not supported`);
} else if (columnNames.has(column)) {
throw new Error(`Duplicate column ${column}`);
} else if (InvalidSQLCharacters.test(column)) {
} else if (columnNames.has(columnName)) {
throw new Error(`Duplicate column ${columnName}`);
} else if (InvalidSQLCharacters.test(columnName)) {
throw new Error(`Invalid characters in column name: $name.${column}`);
}
columnNames.add(column);
columnNames.add(columnName);
}

const indexNames = new Set<string>();
Expand All @@ -112,7 +113,7 @@ export class Table {

for (const column of index.columns) {
if (!columnNames.has(column.name)) {
throw new Error(`Column $name.${column.name} not found for index ${index.name}`);
throw new Error(`Column ${column.name} not found for index ${index.name}`);
}
}

Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2228,14 +2228,6 @@
lodash "^4.17.21"
uuid "3.4.0"

"@journeyapps/react-native-quick-sqlite@^1.1.0":
version "1.1.0"
resolved "https://registry.npmjs.org/@journeyapps/react-native-quick-sqlite/-/react-native-quick-sqlite-1.1.0.tgz#cf4aa6694b7232d0f86e565fdba4e41ef15d80cc"
integrity sha512-Pg6VA6ABC7N5FrNB5eqTgNsKdzzmDSp5aBtnQh1BlcZu7ISPZdCcKo+ZJtKyzTAWpc17LIttvJwxez6zBxUdOw==
dependencies:
lodash "^4.17.21"
uuid "3.4.0"

"@jridgewell/gen-mapping@^0.3.0", "@jridgewell/gen-mapping@^0.3.2":
version "0.3.3"
resolved "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz#7e02e6eb5df901aaedb08514203b096614024098"
Expand Down Expand Up @@ -3611,7 +3603,7 @@ ajv-keywords@^5.1.0:
dependencies:
fast-deep-equal "^3.1.3"

ajv@^8.0.0, ajv@^8.9.0:
ajv@^8.0.0, ajv@^8.11.0, ajv@^8.9.0:
version "8.12.0"
resolved "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1"
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
Expand Down Expand Up @@ -5374,6 +5366,14 @@ expo-asset@~8.10.1:
path-browserify "^1.0.0"
url-parse "^1.5.9"

expo-build-properties@~0.8.3:
version "0.8.3"
resolved "https://registry.npmjs.org/expo-build-properties/-/expo-build-properties-0.8.3.tgz#fbfa156e9619bebda71c66af9a26ebc3490b2365"
integrity sha512-kEDDuAadHqJTkvCGK4fXYHVrePiJO1DjyW95AicmwuGwQvGJydYFbuoauf9ybAU+4UH4arhbce8gHI3ZpIj3Jw==
dependencies:
ajv "^8.11.0"
semver "^7.5.3"

expo-camera@~13.4.4:
version "13.4.4"
resolved "https://registry.npmjs.org/expo-camera/-/expo-camera-13.4.4.tgz#e01ead31a3150398d37e94c307f6937480680690"
Expand Down

0 comments on commit eba6e87

Please sign in to comment.