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

Frames used in migrations #1084

Open
alxndrsn opened this issue Feb 6, 2024 · 6 comments
Open

Frames used in migrations #1084

alxndrsn opened this issue Feb 6, 2024 · 6 comments

Comments

@alxndrsn
Copy link
Contributor

alxndrsn commented Feb 6, 2024

"frames" reflect the current data model, which can change, whereas database migrations operate on historic models which should be fixed to the specific migration.

Observed

$ git grep frames -- lib/model/migrations/
lib/model/migrations/20200220-01-repair-submission-parsing.js:const { Submission } = require('../frames');
lib/model/migrations/20210120-01-instance-names.js:const { Submission } = require('../frames');
lib/model/migrations/20211008-01-track-select-many-options.js:const { Form } = require('../frames');

Expected

Migrations should not rely on application code for their understanding of the database schema.

@matthew-white
Copy link
Member

IIRC we've had a previous round of removing frames from migrations. I think most of the ones that remain are there for XML-parsing, e.g., Submission.fromXml().

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Feb 7, 2024

👍

Could construct(Form.Field) in lib/model/migrations/20211008-01-track-select-many-options.js still be an issue?

const allFields = await db.select('formId', 'path')
.from('form_fields')
.where({ selectMultiple: true })
.groupBy('formId', 'path')
.then(map(construct(Form.Field)));

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Feb 7, 2024

It looks like Submission.fromXml() is still creating a Submission frame internally, so presumably could still present issues in the future.

@matthew-white
Copy link
Member

Could construct(Form.Field) in lib/model/migrations/20211008-01-track-select-many-options.js still be an issue?

I think this is similar to Submission.fromXml() in that Form.Field is used for purposes of XML-parsing. The fields are passed to getSelectMultipleResponses(), which expects an array of frames.

It looks like Submission.fromXml() is still creating a Submission frame internally, so presumably could still present issues in the future.

Conceivably! Though it's a pretty simple use of the frame. Would you want to refactor the XML-parsing so that it doesn't touch frames at all?

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Feb 8, 2024

Would you want to refactor the XML-parsing so that it doesn't touch frames at all?

Yes, I think the ideal is that database migrations are independent of application code, because there is no guarantee which version of the application a particular migration is run with/by. This is especially risky for the application's code defining database structure (in this case frames).

@matthew-white
Copy link
Member

I'm still not sure how much risk there is in this case in practice, but I agree that what you describe would be ideal. And actually, looking at Submission.fromXml(), it does seem very possible to separate the XML-parsing from the frame itself. Submission.fromXml() only assembles a Submission.Partial at the very end, so I could imagine a separate function to do the parsing (which the migration could use), then Submission.fromXml() would just call that function and do its assembling. There are other cases where we have XML-parsing that's completely separate from frames, e.g., getDataset().

The Form.Field frame looks very simple, so I'm not even sure why it's needed in the migration. Maybe because something is calling the frame's isStructural() method? That's probably not essential though / there's got to be an alternative.

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

No branches or pull requests

2 participants