Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(diagnostics): update autogenerated schema and description #328

Merged
merged 6 commits into from
Oct 7, 2024

Conversation

LucDeCaf
Copy link
Contributor

@LucDeCaf LucDeCaf commented Oct 3, 2024

Updates the schema generated by the diagnostics app to use the current Schema and Table syntax.
Also updates the comment above the schema to be more descriptive.

Below is an example of a before/after.

Before:

// This displays the inferred schema currently used by the diagnostics app.
// This is based on downloaded data, rather than the source database.
// If a table is empty, it will not display here.
// Tables and columns are only added here. Nothing is removed until the database is cleared.
new Schema([
  new Table({
    name: 'profiles',
    columns: [
      new Column({ name: 'household_id', type: ColumnType.TEXT })
    ]
  }),
  new Table({
    name: 'grocery_items',
    columns: [
      new Column({ name: 'household_id', type: ColumnType.TEXT }),
      new Column({ name: 'created_at', type: ColumnType.TEXT }),
      new Column({ name: 'name', type: ColumnType.TEXT }),
      new Column({ name: 'comment', type: ColumnType.TEXT })
    ]
  }),
  new Table({
    name: 'groups',
    columns: [
      new Column({ name: 'household_id', type: ColumnType.TEXT }),
      new Column({ name: 'created_at', type: ColumnType.TEXT }),
      new Column({ name: 'name', type: ColumnType.TEXT }),
      new Column({ name: 'index', type: ColumnType.INTEGER }),
      new Column({ name: 'is_aisle', type: ColumnType.INTEGER })
    ]
  }),
  new Table({
    name: 'groups_grocery_items',
    columns: [
      new Column({ name: 'household_id', type: ColumnType.TEXT }),
      new Column({ name: 'group_id', type: ColumnType.TEXT }),
      new Column({ name: 'grocery_item_id', type: ColumnType.TEXT })
    ]
  })
])

After:

/**
 * This is the inferred schema of the data received by the diagnostics app.
 * Because this schema is generated on-the-fly based on the data received by the app, it can
 * be incomplete and should NOT be relied upon as a source of truth for your app schema.
 * If a table is empty, it will not be shown here.
 * Tables and columns are only added here. Nothing is removed until the database is cleared.
 */
export const profiles = new Table(
  {
    // id column (text) is automatically included
    household_id: column.text
  },
  { indexes: {} }
);

export const grocery_items = new Table(
  {
    // id column (text) is automatically included
    household_id: column.text,
    created_at: column.text,
    name: column.text,
    comment: column.text
  },
  { indexes: {} }
);

export const groups = new Table(
  {
    // id column (text) is automatically included
    household_id: column.text,
    created_at: column.text,
    name: column.text,
    index: column.integer,
    is_aisle: column.integer
  },
  { indexes: {} }
);

export const groups_grocery_items = new Table(
  {
    // id column (text) is automatically included
    household_id: column.text,
    group_id: column.text,
    grocery_item_id: column.text
  },
  { indexes: {} }
);

export const AppSchema = new Schema({
  profiles,
  grocery_items,
  groups,
  groups_grocery_items
});

export type Database = (typeof AppSchema)['types'];

Copy link

changeset-bot bot commented Oct 3, 2024

🦋 Changeset detected

Latest commit: 89dd672

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/diagnostics-app Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@DominicGBauer
Copy link
Collaborator

DominicGBauer commented Oct 4, 2024

LGTM,

We will want to adapt the generators from https://github.com/powersync-ja/powersync-service/blob/d8e8c4d16e649ca45ae1a95980b66f7b453835c3/packages/sync-rules/src/SchemaGenerator.ts#L5 to allow for the case of not using sync rules to generate schema, as is the case in here. This will avoid us duplicating the schema generation in future and would allow us to import the generators from @powersync/service-sync-rules which would keep the diagnostics app schema generation always up to date.

DominicGBauer
DominicGBauer previously approved these changes Oct 4, 2024
@benitav benitav merged commit aad9ba5 into powersync-ja:main Oct 7, 2024
@LucDeCaf LucDeCaf deleted the feat/update-diagnostics-schema branch October 7, 2024 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants