-
Notifications
You must be signed in to change notification settings - Fork 119
feat(x2a): implement cascading invalidation #4488
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
Merged
mareklibra
merged 3 commits into
redhat-developer:main
from
yray-pixel:CascadingInvaladation
Sep 7, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@red-hat-developer-hub/backstage-plugin-x2a-backend': patch | ||
| '@red-hat-developer-hub/backstage-plugin-x2a-common': patch | ||
| '@red-hat-developer-hub/backstage-plugin-x2a-node': patch | ||
| '@red-hat-developer-hub/backstage-plugin-x2a': patch | ||
| --- | ||
|
|
||
| Downstream phase jobs are automatically marked as stale when an upstream phase completes successfully. |
155 changes: 155 additions & 0 deletions
155
workspaces/x2a/plugins/x2a-backend/migrations/2026081900_expand_jobs_constraints.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import type { Knex } from 'knex'; | ||
|
|
||
| const PHASES = [ | ||
| 'init', | ||
| 'analyze', | ||
| 'migrate', | ||
| 'publish', | ||
| 'adversarial-analyze', | ||
| 'adversarial-migrate', | ||
| ]; | ||
|
|
||
| const EXTENDED_STATUSES = [ | ||
| 'pending', | ||
| 'running', | ||
| 'success', | ||
| 'error', | ||
| 'cancelled', | ||
| 'stale', | ||
| ]; | ||
|
|
||
| const ORIGINAL_STATUSES = [ | ||
| 'pending', | ||
| 'running', | ||
| 'success', | ||
| 'error', | ||
| 'cancelled', | ||
| ]; | ||
|
|
||
| function createJobsTable( | ||
| table: Knex.CreateTableBuilder, | ||
| statuses: string[], | ||
| ): void { | ||
| table.uuid('id').primary(); | ||
| table.text('log'); | ||
| table.timestamp('started_at').notNullable(); | ||
| table.timestamp('finished_at'); | ||
| table.string('status').notNullable().defaultTo('pending').checkIn(statuses); | ||
| table.string('phase').notNullable().defaultTo('init').checkIn(PHASES); | ||
| table | ||
| .uuid('project_id') | ||
| .notNullable() | ||
| .references('id') | ||
| .inTable('projects') | ||
| .onDelete('CASCADE') | ||
| .index(); | ||
| table | ||
| .uuid('module_id') | ||
| .nullable() | ||
| .references('id') | ||
| .inTable('modules') | ||
| .onDelete('CASCADE') | ||
| .index(); | ||
| table.text('error_details'); | ||
| table.text('telemetry'); | ||
| table.string('k8s_job_name'); | ||
| table.string('callback_token'); | ||
| table.string('commit_id').nullable(); | ||
| table.index('started_at'); | ||
| table.index('finished_at'); | ||
| table.index('status'); | ||
| table.index('phase'); | ||
| table.index('k8s_job_name'); | ||
| } | ||
|
|
||
| async function recreateJobsTableSqlite( | ||
| knex: Knex, | ||
| statuses: string[], | ||
| staging: string, | ||
| ): Promise<void> { | ||
| // staging must be unique across all migrations — SQLite index names are | ||
| // global and survive table renames, so reusing a prior staging name causes | ||
| // an "index already exists" error on the next recreate. | ||
| await knex.schema.raw('PRAGMA foreign_keys = OFF'); | ||
| try { | ||
| await knex.schema.createTable(staging, table => | ||
| createJobsTable(table, statuses), | ||
| ); | ||
| await knex.schema.raw( | ||
| `INSERT INTO ${staging} (id, log, started_at, finished_at, status, phase, error_details, telemetry, k8s_job_name, callback_token, commit_id, project_id, module_id)` + | ||
| ` SELECT id, log, started_at, finished_at, status, phase, error_details, telemetry, k8s_job_name, callback_token, commit_id, project_id, module_id FROM jobs`, | ||
| ); | ||
| await knex.schema.dropTable('jobs'); | ||
| await knex.schema.raw(`ALTER TABLE ${staging} RENAME TO jobs`); | ||
| } finally { | ||
| await knex.schema.raw('PRAGMA foreign_keys = ON'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Expands the jobs.status CHECK constraint to include 'stale', | ||
| * needed for cascading invalidation of downstream phase jobs. | ||
| * | ||
| * @public | ||
| */ | ||
| export async function up(knex: Knex): Promise<void> { | ||
| const client = knex.client.config.client; | ||
|
|
||
| if (client === 'better-sqlite3') { | ||
| await recreateJobsTableSqlite( | ||
| knex, | ||
| EXTENDED_STATUSES, | ||
| 'jobs_status_expanded', | ||
| ); | ||
| } else { | ||
| await knex.raw( | ||
| `ALTER TABLE jobs DROP CONSTRAINT IF EXISTS jobs_status_check`, | ||
| ); | ||
| await knex.raw( | ||
| `ALTER TABLE jobs ADD CONSTRAINT jobs_status_check CHECK (status IN ('pending', 'running', 'success', 'error', 'cancelled', 'stale'))`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Reverts the jobs.status CHECK constraint to exclude 'stale'. | ||
| * | ||
| * @public | ||
| */ | ||
| export async function down(knex: Knex): Promise<void> { | ||
| // Stale rows must be converted before reinstating the constraint; | ||
| await knex('jobs').where('status', 'stale').update({ status: 'success' }); | ||
|
|
||
| const client = knex.client.config.client; | ||
|
|
||
| if (client === 'better-sqlite3') { | ||
| await recreateJobsTableSqlite( | ||
| knex, | ||
| ORIGINAL_STATUSES, | ||
| 'jobs_status_contracted', | ||
| ); | ||
| } else { | ||
| await knex.raw( | ||
| `ALTER TABLE jobs DROP CONSTRAINT IF EXISTS jobs_status_check`, | ||
| ); | ||
| await knex.raw( | ||
| `ALTER TABLE jobs ADD CONSTRAINT jobs_status_check CHECK (status IN ('pending', 'running', 'success', 'error', 'cancelled'))`, | ||
|
mareklibra marked this conversation as resolved.
|
||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.