Skip to content

Commit b5ceb84

Browse files
authored
Remove old schema v1 syntax (#1004)
1 parent e3d4f0c commit b5ceb84

25 files changed

Lines changed: 332 additions & 741 deletions

File tree

.changeset/clean-poems-dress.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@powersync/attachments': major
3+
'@powersync/react-native': major
4+
'@powersync/common': major
5+
'@powersync/web': major
6+
'@powersync/capacitor': minor
7+
'@powersync/node': minor
8+
'@powersync/nuxt': minor
9+
---
10+
11+
Remove the deprecated table v1 syntax. To create tables based on column arrays, use the new ResolvedTable class.

demos/angular-supabase-todolist/src/app/powersync.service.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { Injectable } from '@angular/core';
22
import {
3-
AbstractPowerSyncDatabase,
4-
Column,
5-
ColumnType,
3+
column,
4+
CommonPowerSyncDatabase,
65
createConsoleLogger,
7-
Index,
8-
IndexedColumn,
96
LogLevels,
107
PowerSyncBackendConnector,
118
PowerSyncDatabase,
@@ -36,35 +33,31 @@ export interface TodoRecord {
3633
export const LISTS_TABLE = 'lists';
3734
export const TODOS_TABLE = 'todos';
3835

39-
export const AppSchema = new Schema([
40-
new Table({
41-
name: TODOS_TABLE,
42-
columns: [
43-
new Column({ name: 'list_id', type: ColumnType.TEXT }),
44-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
45-
new Column({ name: 'completed_at', type: ColumnType.TEXT }),
46-
new Column({ name: 'description', type: ColumnType.TEXT }),
47-
new Column({ name: 'completed', type: ColumnType.INTEGER }),
48-
new Column({ name: 'created_by', type: ColumnType.TEXT }),
49-
new Column({ name: 'completed_by', type: ColumnType.TEXT })
50-
],
51-
indexes: [new Index({ name: 'list', columns: [new IndexedColumn({ name: 'list_id' })] })]
52-
}),
53-
new Table({
54-
name: LISTS_TABLE,
55-
columns: [
56-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
57-
new Column({ name: 'name', type: ColumnType.TEXT }),
58-
new Column({ name: 'owner_id', type: ColumnType.TEXT })
59-
]
36+
export const AppSchema = new Schema({
37+
[TODOS_TABLE]: new Table(
38+
{
39+
list_id: column.text,
40+
created_at: column.text,
41+
completed_at: column.text,
42+
description: column.text,
43+
completed: column.integer,
44+
created_by: column.text,
45+
completed_by: column.text
46+
},
47+
{ indexes: { list: ['list_id'] } }
48+
),
49+
[LISTS_TABLE]: new Table({
50+
created_at: column.text,
51+
name: column.text,
52+
owner_id: column.text
6053
})
61-
]);
54+
});
6255

6356
@Injectable({
6457
providedIn: 'root'
6558
})
6659
export class PowerSyncService {
67-
db: AbstractPowerSyncDatabase;
60+
db: CommonPowerSyncDatabase;
6861

6962
constructor() {
7063
const factory = new WASQLiteOpenFactory({

demos/react-multi-client/src/definitions/Schema.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Column, ColumnType, Schema, Table } from '@powersync/web';
1+
import { column, Schema, Table } from '@powersync/web';
22

33
export const TABLE_NAME = 'pebbles';
44
export const MAX_PEBBLES = 5;
@@ -19,29 +19,24 @@ export interface PebbleDef {
1919
user_id: string;
2020
}
2121

22-
export const AppSchema = new Schema([
23-
new Table({
24-
name: TABLE_NAME,
25-
columns: [
26-
new Column({ name: 'shape', type: ColumnType.TEXT }),
27-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
28-
new Column({ name: 'user_id', type: ColumnType.TEXT })
29-
]
22+
export const AppSchema = new Schema({
23+
[TABLE_NAME]: new Table({
24+
shape: column.text,
25+
created_at: column.text,
26+
user_id: column.text
3027
}),
31-
new Table({
32-
name: 'operations',
33-
columns: [
34-
new Column({ name: 'operation', type: ColumnType.TEXT }),
35-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
36-
new Column({ name: 'user_id', type: ColumnType.TEXT })
37-
]
28+
operations: new Table({
29+
operation: column.text,
30+
created_at: column.text,
31+
user_id: column.text
3832
}),
39-
new Table({
40-
name: 'settings',
41-
localOnly: true,
42-
columns: [new Column({ name: 'initialized', type: ColumnType.INTEGER })]
43-
})
44-
]);
33+
settings: new Table(
34+
{
35+
initialized: column.integer
36+
},
37+
{ localOnly: true }
38+
)
39+
});
4540

4641
export function randomPebbleShape(): Shape {
4742
const colors = Object.values(Shape);

packages/attachments/src/Schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Column, ColumnType, Table, TableOptions } from '@powersync/common';
1+
import { Column, ColumnType, ResolvedTable, ResolvedTableOptions } from '@powersync/common';
22

33
export const ATTACHMENT_TABLE = 'attachments';
44

@@ -20,12 +20,12 @@ export enum AttachmentState {
2020
ARCHIVED = 4 // Attachment has been orphaned, i.e. the associated record has been deleted
2121
}
2222

23-
export interface AttachmentTableOptions extends Omit<TableOptions, 'name' | 'columns'> {
23+
export interface AttachmentTableOptions extends Omit<ResolvedTableOptions, 'name' | 'columns'> {
2424
name?: string;
2525
additionalColumns?: Column[];
2626
}
2727

28-
export class AttachmentTable extends Table {
28+
export class AttachmentTable extends ResolvedTable {
2929
constructor(options?: AttachmentTableOptions) {
3030
super({
3131
...options,

0 commit comments

Comments
 (0)