Skip to content

[1r] DB migrations refactor#9

Merged
JonoPrest merged 9 commits into
mainfrom
jp/db-migrations-refactor
Jun 6, 2024
Merged

[1r] DB migrations refactor#9
JonoPrest merged 9 commits into
mainfrom
jp/db-migrations-refactor

Conversation

@JonoPrest

Copy link
Copy Markdown
Collaborator

First step of remodelling db interaction to be more composable and modular

Tables are now defined in a rescript structure.
Migrations are derived from the rescript structure
The model should be more composable and less hidden behind codegen logic. I decided it's ok for Migration queries to be composed with sql.unsafe since we don't need any prepared statements or injection protection. For the next step which is creating composeable read/write/delete queries these will use dynamic queries which do have prepared statements and injection protection.

Next steps

Hasura tracking via table structure
DbFunctions composed via new "Table" model
All in memory store interaction, serializers/deserializers and stores created via table structure
Trying to offload generated code and make more static to make parts moduler.

@JonoPrest JonoPrest requested review from DZakh and JasoonS May 29, 2024 16:19
@JonoPrest

Copy link
Copy Markdown
Collaborator Author

@JasoonS something has changed with the pipeline here... it's breaking pretty early in the workflow.

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Also, the CI should work correctly now, after Jason updated secrets.

{{/each}}
})

let rowsSchema = S.array({{entity.name.uncapitalized}}EntitySchema)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let rowsSchema = S.array({{entity.name.uncapitalized}}EntitySchema)
let rowsSchema = S.array(schema)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nice! I actually fixed this in the PR stacked above this. I didn't pick it up here because this was not being used until I connected it.

I think if you're happy with taking the commit from the stacked pr then rather do that to avoid conflicts

Comment on lines +13 to +23
type row = {
{{#each entity.params as | param |}}
{{#unless param.is_derived_from }}{{param.field_name.uncapitalized}}{{#if param.is_entity_field}}_id{{/if}}: {{param.type_rescript}},{{/unless}}
{{/each}}
}

let schema = S.object((. s) => {
{{#each entity.params as | param |}}
{{#unless param.is_derived_from }}{{param.field_name.uncapitalized}}{{#if param.is_entity_field}}_id{{/if}}: s.field("{{param.field_name.uncapitalized}}{{#if param.is_entity_field}}_id{{/if}}", {{param.type_rescript_schema}}),{{/unless}}
{{/each}}
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a feeling that it might be better to create the type, schemas, and other entity elements on the Rust side.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes I agree! I think we should migrate those changes we made on the fuel indexer to evm. It's much nicer. And will be more powerful for nested structs (right now we just inline nested structs as tuples instead of providing a record type for them)

{{entity.name.capitalized}}.table,
{{/each}}
]
let schema = Schema.make(allTables)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A little bit confusing to have it the same name as rescript-schema

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah good point 👍🏼 we can change the name. Any suggestion for a name? This module is meant to coordinate relationships between entity tables as defined in the graphql schema

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Also does it override namespace for rescript schema or not?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also does it override namespace for rescript schema or not?

No, it's not.

This module is meant to coordinate relationships between entity tables as defined in the graphql schema

dbSchema maybe?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keeping it like this also works

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok cool, lets do DbSchema but I will change in my next PR not here 👍🏼

@JonoPrest JonoPrest merged commit 4ef12e9 into main Jun 6, 2024
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.

2 participants