Skip to content

Migrate old instructions column - #981

Open
zetter-rpf wants to merge 2 commits into
mainfrom
migrate-instructions
Open

Migrate old instructions column#981
zetter-rpf wants to merge 2 commits into
mainfrom
migrate-instructions

Conversation

@zetter-rpf

@zetter-rpf zetter-rpf commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Status

What's changed?

This is tidy up after introducing instruction Steps to migrate all data into a single column.

By adding instructions to ignored columns tests will fail if anything is accessing it and we can later drop the old column in another deploy.

Note that instruction steps is a JSONB column, that might contain an array of instruction objects, or a single string. Currently editor-ui handles these different formats. We could later do another migration to wrap the strings into an array which would allow us to simplify the frontend.

Previously, projects created before instruction_steps existed only
had their instructions stored in the legacy text column, so
Project#instructions had to fall back to it at read time.

This change adds a data migration that copies the legacy instructions
value into instruction_steps for any row where instruction_steps is
still null, so every project can be read from instruction_steps alone.
This is a step toward removing the instructions column entirely.
Previously, Project#instructions fell back to the legacy text column
for rows written before instruction_steps existed, and the setter
kept writing that column too. Now that instruction_steps has been
backfilled for every project, that fallback is unnecessary and would
break once the column is dropped.

This change marks instructions as an ignored column and simplifies
the instructions accessor and mutator to delegate directly to
instruction_steps, removing the last runtime dependency on the
legacy column so it can be safely dropped in a follow-up migration.
@cla-bot cla-bot Bot added the cla-signed label Aug 25, 2026
@zetter-rpf zetter-rpf changed the title Migrate instructions Migrate old instructions column Aug 25, 2026
@github-actions

Copy link
Copy Markdown

Test coverage

93.43% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/32862372099

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates legacy projects.instructions (text) into the newer projects.instruction_steps (jsonb) and updates the Project model to stop reading/writing the legacy column, preparing for dropping it in a later deploy.

Changes:

  • Add a data migration to backfill instruction_steps from the legacy instructions column.
  • Update Project to ignore the legacy instructions column and make instructions/instructions= delegate to instruction_steps.
  • Simplify the Project#instructions model spec to only validate delegation to instruction_steps.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
app/models/project.rb Ignores the legacy instructions column and delegates instructions accessors to instruction_steps.
db/migrate/20260825144345_backfill_instruction_steps_from_instructions.rb Backfills instruction_steps from instructions for existing rows.
db/schema.rb Updates schema version after adding the migration.
spec/models/project_spec.rb Updates model tests to reflect the new delegation-only behavior.
Suppressed comments (1)

db/migrate/20260825144345_backfill_instruction_steps_from_instructions.rb:13

  • down is currently a no-op, so rolling back this migration would report success while leaving data changed. If the backfill can’t be safely reversed, it should explicitly raise ActiveRecord::IrreversibleMigration to avoid a misleading rollback.
  def down
  end

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +5 to +9
execute <<~SQL.squish
UPDATE projects
SET instruction_steps = to_jsonb(instructions)
WHERE instruction_steps IS NULL AND instructions IS NOT NULL
SQL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm going to be bold and try to run this as I expect the migration to run within a few seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants