Repository navigation
[AGE-2882] Add artifact metadata tables #1435
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
Open
rutvij-menavlikar
wants to merge
13
commits into
main
Choose a base branch
from
rutvij/age-2882_1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b59acdb
[AGE-2882] Add artifact tables and DB store
rutvij-menavlikar dd453a9
[AGE-2882] Scope PR to artifact table migrations
rutvij-menavlikar 4996962
[AGE-2882] Drop derivable artifact columns
rutvij-menavlikar cc12fa0
[AGE-2882] Move creator columns to artifact; index version status
rutvij-menavlikar 882a871
[AGE-2882] Drop down migrations
rutvij-menavlikar 1f7d177
[AGE-2882] Add created_at to artifact_file
rutvij-menavlikar b3e76a2
[AGE-2882] Index artifact list by creator
rutvij-menavlikar 1d9e88c
[AGE-2882] Re-add artifact down migrations
rutvij-menavlikar 08a0fac
[AGE-2882] Drop artifact_version.created_by_turn_id
rutvij-menavlikar 3ebeec5
[AGE-2882] Drop artifact_file and version status; add storage_prefix
rutvij-menavlikar 6176abd
[AGE-2882] Drop artifact_version.entrypoint
rutvij-menavlikar c76e11a
[AGE-2882] Add artifact title index
rutvij-menavlikar 3307efc
[AGE-2882] Remove artifact title index
rutvij-menavlikar 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,5 @@ | ||
| --- | ||
| "@truefoundry/trueforge": patch | ||
| --- | ||
|
|
||
| Add `artifact` and `artifact_version` tables. |
45 changes: 45 additions & 0 deletions
45
packages/trueforge/src/db/postgres/migrations/20261119_000001_artifact.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,45 @@ | ||
| import { sql, type Kysely } from 'kysely'; | ||
|
|
||
| /** Artifact metadata; file bytes live in object storage. No FK to session: artifacts outlive it. */ | ||
| export async function up(db: Kysely<unknown>): Promise<void> { | ||
| await sql`SET LOCAL lock_timeout = '5s'`.execute(db); | ||
|
|
||
| await db.schema | ||
| .createTable('artifact') | ||
| .addColumn('id', 'text', col => col.notNull()) | ||
| .addColumn('tenant_id', 'text', col => col.notNull()) | ||
| .addColumn('slug', 'text', col => col.notNull()) | ||
| .addColumn('title', 'text', col => col.notNull()) | ||
| .addColumn('latest_version', 'integer', col => col.notNull()) | ||
| .addColumn('created_by_subject', 'jsonb', col => col.notNull()) | ||
| .addColumn('created_by_session_id', 'text', col => col.notNull()) | ||
| .addColumn('created_at', 'timestamptz', col => col.notNull()) | ||
| .addColumn('updated_at', 'timestamptz', col => col.notNull()) | ||
| .addPrimaryKeyConstraint('artifact_pkey', ['id']) | ||
| .addUniqueConstraint('artifact_tenant_slug_uq', ['tenant_id', 'slug']) | ||
| .execute(); | ||
|
|
||
| await sql` | ||
| CREATE INDEX artifact_list_idx | ||
| ON artifact (tenant_id, (created_by_subject->>'subject_id'), updated_at DESC, id) | ||
| `.execute(db); | ||
| await sql`CREATE INDEX artifact_session_idx ON artifact (tenant_id, created_by_session_id)`.execute(db); | ||
|
rutvij-menavlikar marked this conversation as resolved.
Resolved
|
||
| await db.schema | ||
| .createTable('artifact_version') | ||
| .addColumn('artifact_id', 'text', col => col.notNull()) | ||
| .addColumn('version', 'integer', col => col.notNull()) | ||
| .addColumn('storage_prefix', 'text', col => col.notNull()) | ||
| .addColumn('total_bytes', 'bigint', col => col.notNull()) | ||
| .addColumn('created_at', 'timestamptz', col => col.notNull()) | ||
| .addPrimaryKeyConstraint('artifact_version_pkey', ['artifact_id', 'version']) | ||
| .addForeignKeyConstraint('artifact_version_artifact_id_fkey', ['artifact_id'], 'artifact', ['id'], fk => | ||
| fk.onDelete('cascade'), | ||
| ) | ||
| .execute(); | ||
| } | ||
|
|
||
| export async function down(db: Kysely<unknown>): Promise<void> { | ||
| await sql`SET LOCAL lock_timeout = '5s'`.execute(db); | ||
| await db.schema.dropTable('artifact_version').ifExists().execute(); | ||
| await db.schema.dropTable('artifact').ifExists().execute(); | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
51 changes: 51 additions & 0 deletions
51
packages/trueforge/src/db/sqlite/migrations/20261119_000001_artifact.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,51 @@ | ||
| import { sql, type Kysely } from 'kysely'; | ||
|
|
||
| /** Artifact metadata (mirrors Postgres). STRICT tables; jsonb as BLOB; timestamps as ISO TEXT. */ | ||
| export async function up(db: Kysely<unknown>): Promise<void> { | ||
| await db.transaction().execute(async trx => { | ||
| await sql` | ||
| CREATE TABLE artifact ( | ||
| id TEXT NOT NULL, | ||
| tenant_id TEXT NOT NULL, | ||
| slug TEXT NOT NULL, | ||
| title TEXT NOT NULL, | ||
| latest_version INTEGER NOT NULL, | ||
| created_by_subject BLOB NOT NULL, | ||
| created_by_session_id TEXT NOT NULL, | ||
| created_at TEXT NOT NULL, | ||
| updated_at TEXT NOT NULL, | ||
| PRIMARY KEY (id), | ||
| CONSTRAINT artifact_tenant_slug_uq UNIQUE (tenant_id, slug) | ||
| ) STRICT | ||
| `.execute(trx); | ||
|
|
||
| await sql` | ||
| CREATE INDEX artifact_list_idx | ||
| ON artifact (tenant_id, json_extract(created_by_subject, '$.subject_id'), updated_at DESC, id) | ||
| `.execute(trx); | ||
| await sql`CREATE INDEX artifact_session_idx ON artifact (tenant_id, created_by_session_id)`.execute(trx); | ||
| await sql` | ||
| CREATE TABLE artifact_version ( | ||
| artifact_id TEXT NOT NULL, | ||
| version INTEGER NOT NULL, | ||
| storage_prefix TEXT NOT NULL, | ||
| total_bytes INTEGER NOT NULL, | ||
| created_at TEXT NOT NULL, | ||
| PRIMARY KEY (artifact_id, version), | ||
| FOREIGN KEY (artifact_id) REFERENCES artifact (id) ON DELETE CASCADE | ||
| ) STRICT | ||
| `.execute(trx); | ||
| }); | ||
| } | ||
|
|
||
| export async function down(db: Kysely<unknown>): Promise<void> { | ||
| await sql`PRAGMA foreign_keys = OFF`.execute(db); | ||
| try { | ||
| await db.transaction().execute(async trx => { | ||
| await sql`DROP TABLE IF EXISTS artifact_version`.execute(trx); | ||
| await sql`DROP TABLE IF EXISTS artifact`.execute(trx); | ||
| }); | ||
| } finally { | ||
| await sql`PRAGMA foreign_keys = ON`.execute(db); | ||
| } | ||
| } |
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.