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: add schema definition for project keys table #169

Merged
merged 5 commits into from
Aug 14, 2023

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Aug 14, 2023

Closes #165

Questions:

  • should we rename the project table to something like project_info? Didn't think it was highly necessary so only updated the associated variable name for now
  • what should the table name be? i.e. projectKeys (consistent with our naming conventions) vs project_keys (consistent with sqlite table naming conventions. also, singular or plural here?
  • should it be projectKey column be named projectId instead? Should it be more specific i.e. projectPublicKey?
  • would it be helpful to add a note in https://github.com/digidem/mapeo-core-next/blob/38ab9de01c83f99cd161c0a76317c395209b097c/src/core-manager/index.js#L13 about updating this file if more namespaces are created, if applicable?

@achou11 achou11 requested a review from gmaclennan August 14, 2023 15:15
@achou11
Copy link
Member Author

achou11 commented Aug 14, 2023

Getting a test failure for https://github.com/digidem/mapeo-core-next/blob/38ab9de01c83f99cd161c0a76317c395209b097c/tests/schema.js#L87

Does there need to be a backlink table for this new table?

@gmaclennan
Copy link
Member

Does there need to be a backlink table for this new table?

No, that test needs updated. There only need to be backlink tables for tables that index data types from Mapeo Schema. This test is a bit fragile and more of a reminder - open to ideas about a sensible way to exclude a table like this from needing a backlink table.

@gmaclennan
Copy link
Member

  • should we rename the project table to something like project_info? Didn't think it was highly necessary so only updated the associated variable name for now

Yes, I think name is projectSetting and also rename the schema name in @mapeo/schema to projectSetting to avoid confusion.

  • what should the table name be? i.e. projectKeys (consistent with our naming conventions) vs project_keys (consistent with sqlite table naming conventions. also, singular or plural here?

We're naming all our other tables in camelcase. Don't think we need to stick with any conventions here, just what is easy and consistent. I think plural makes sense (e.g. projectKeys) because each row is multiple keys - I know our other table names are singular, but I think the plural here is actually projectKeyses 😆

  • should it be projectKey column be named projectId instead? Should it be more specific i.e. projectPublicKey?

Yes, let's rename it projectId. We have been following a pattern where key = Buffer, id = string. We need to define what a projectId is - should it be a hex representation of the project public key, or a hex of the discovery key, or a base32 of the project key (this is what hypercore uses as coreId), or should it be a hash of the project key with something else, so that knowing the project ID does not give you the information for discovery?

Yes, good idea. Or dynamically generate the table schema based on that constant?

const columns = {
   projectKey: text('projectKey').notNull().primaryKey(),
   projectSecretKey: blob('projectSecretKey'),
}

for (const namespace of NAMESPACES) {
  const columnName = namespace + 'EncryptionKey'
  columns[columnName] = blob(columnName)
}

@achou11
Copy link
Member Author

achou11 commented Aug 14, 2023

No, that test needs updated. There only need to be backlink tables for tables that index data types from Mapeo Schema. This test is a bit fragile and more of a reminder - open to ideas about a sensible way to exclude a table like this from needing a backlink table.

I don't have any elegant ideas here. Only ones I have are:

  1. Hardcode the exclusion in the test
  2. Create separate files for tables that require backlinks e.g.
- schema/
|--- client.js # projectKey table would still stay here, re-export project and project backlink tables from requiresBacklink/client.js
|--- project.js
|--- requiresBacklink/
     |--- client.js # project and project backlink tables are exported here
     |--- project.js

then update the test to only import from the requiresBacklink/ directory 🤷 note that requiresBacklink is arbitrary (please suggest a better name if possible)

EDIT: looks like (2) doesn't work well with Drizzle's CLI (i.e. when re-exporting like export * from './requiresBackLink/client.js'), so maybe that isn't the way to go...

EDIT 2: decided to update the tests to filter using @mapeo/schema as the source of truth for determining data type schemas

@achou11
Copy link
Member Author

achou11 commented Aug 14, 2023

We need to define what a projectId is - should it be a hex representation of the project public key, or a hex of the discovery key, or a base32 of the project key (this is what hypercore uses as coreId), or should it be a hash of the project key with something else, so that knowing the project ID does not give you the information for discovery?

Might be better if I create a separate issue for this since nothing in this PR is actually going to affect that

EDIT: add any thoughts on this to #171

@achou11 achou11 force-pushed the 165/project-keys-drizzle-schema branch from 06ec2f3 to 4a2b140 Compare August 14, 2023 19:53
Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@achou11
Copy link
Member Author

achou11 commented Aug 14, 2023

Yes, I think name is projectSetting and also rename the schema name in @mapeo/schema to projectSetting to avoid confusion.

Going to merge without addressing this here. There's an issue opened in the schema repo to track and eventually address: https://github.com/digidem/mapeo-schema/issues/114

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.

Create a drizzle table schema definition for project keys
2 participants