-
Notifications
You must be signed in to change notification settings - Fork 0
Automation Versioning #151
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| -- Add active_version_id to stored_automation | ||
| ALTER TABLE `stored_automation` ADD `active_version_id` varchar(36); | ||
| --> statement-breakpoint | ||
| ALTER TABLE `stored_automation` DROP COLUMN `draft`; | ||
| --> statement-breakpoint | ||
| ALTER TABLE `stored_automation` DROP COLUMN `version`; | ||
| --> statement-breakpoint | ||
| CREATE TABLE `automation_versions` ( | ||
| `activated_from_version_id` varchar(36), | ||
| `automation_id` varchar(36) NOT NULL, | ||
| `body` text NOT NULL, | ||
| `date` timestamp NOT NULL, | ||
| `documentation` text, | ||
| `has_code_change` varchar(10) NOT NULL DEFAULT 'true', | ||
| `has_notes_change` varchar(10) NOT NULL DEFAULT 'false', | ||
| `id` varchar(36) NOT NULL, | ||
| `is_active` varchar(10) NOT NULL DEFAULT 'false', | ||
| `is_draft` varchar(10) NOT NULL DEFAULT 'false', | ||
| `name` varchar(255), | ||
| `notes` text, | ||
| `parent_version_id` varchar(36), | ||
| `was_auto_saved` varchar(10) NOT NULL DEFAULT 'false', | ||
| `written_by_ai` varchar(10) NOT NULL DEFAULT 'false', | ||
| CONSTRAINT `automation_versions_id` PRIMARY KEY(`id`) | ||
| ); | ||
| --> statement-breakpoint | ||
| -- Seed initial versions from existing automations | ||
| INSERT INTO `automation_versions` ( | ||
| `id`, `automation_id`, `body`, `date`, `documentation`, | ||
| `has_code_change`, `has_notes_change`, | ||
| `is_active`, `is_draft`, `name`, | ||
| `was_auto_saved`, `written_by_ai` | ||
| ) | ||
| SELECT | ||
| UUID(), | ||
| `id`, | ||
| `body`, | ||
| `create_date`, | ||
| `documentation`, | ||
| 'true', 'false', | ||
| 'true', 'false', 'Initial version', | ||
| 'false', 'false' | ||
| FROM `stored_automation`; | ||
| --> statement-breakpoint | ||
| -- Point each automation at its initial version | ||
| UPDATE `stored_automation` sa | ||
| JOIN `automation_versions` av ON av.`automation_id` = sa.`id` | ||
| SET sa.`active_version_id` = av.`id`; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| -- Add active_version_id to stored_automation | ||
| ALTER TABLE "stored_automation" ADD "active_version_id" text; | ||
| --> statement-breakpoint | ||
| ALTER TABLE "stored_automation" DROP COLUMN "draft"; | ||
| --> statement-breakpoint | ||
| ALTER TABLE "stored_automation" DROP COLUMN "version"; | ||
| --> statement-breakpoint | ||
| CREATE TABLE "automation_versions" ( | ||
| "activated_from_version_id" text, | ||
| "automation_id" text NOT NULL, | ||
| "body" text NOT NULL, | ||
| "date" timestamp NOT NULL, | ||
| "documentation" text, | ||
| "has_code_change" text NOT NULL DEFAULT 'true', | ||
| "has_notes_change" text NOT NULL DEFAULT 'false', | ||
| "id" text PRIMARY KEY NOT NULL, | ||
| "is_active" text NOT NULL DEFAULT 'false', | ||
| "is_draft" text NOT NULL DEFAULT 'false', | ||
| "name" text, | ||
| "notes" text, | ||
| "parent_version_id" text, | ||
| "was_auto_saved" text NOT NULL DEFAULT 'false', | ||
| "written_by_ai" text NOT NULL DEFAULT 'false' | ||
| ); | ||
| --> statement-breakpoint | ||
| -- Seed initial versions from existing automations | ||
| INSERT INTO "automation_versions" ( | ||
| "id", "automation_id", "body", "date", "documentation", | ||
| "has_code_change", "has_notes_change", | ||
| "is_active", "is_draft", "name", | ||
| "was_auto_saved", "written_by_ai" | ||
| ) | ||
| SELECT | ||
| gen_random_uuid()::text, | ||
| "id", | ||
| "body", | ||
| "create_date", | ||
| "documentation", | ||
| 'true', 'false', | ||
| 'true', 'false', 'Initial version', | ||
| 'false', 'false' | ||
| FROM "stored_automation"; | ||
| --> statement-breakpoint | ||
| -- Point each automation at its initial version | ||
| UPDATE "stored_automation" sa | ||
| SET "active_version_id" = av."id" | ||
| FROM "automation_versions" av | ||
| WHERE av."automation_id" = sa."id"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ALTER TABLE `stored_automation` ADD `active_version_id` text; | ||
| --> statement-breakpoint | ||
| CREATE TABLE `automation_versions` ( | ||
| `activated_from_version_id` text, | ||
| `automation_id` text NOT NULL, | ||
| `body` text NOT NULL, | ||
| `date` text NOT NULL, | ||
| `documentation` text, | ||
| `has_code_change` text NOT NULL DEFAULT 'true', | ||
| `has_notes_change` text NOT NULL DEFAULT 'false', | ||
| `id` text PRIMARY KEY NOT NULL, | ||
| `is_active` text NOT NULL DEFAULT 'false', | ||
| `is_draft` text NOT NULL DEFAULT 'false', | ||
| `name` text, | ||
| `notes` text, | ||
| `parent_version_id` text, | ||
| `was_auto_saved` text NOT NULL DEFAULT 'false', | ||
| `written_by_ai` text NOT NULL DEFAULT 'false' | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { TServiceParams } from "@digital-alchemy/core"; | ||
| import { Type } from "@sinclair/typebox"; | ||
|
|
||
| const params = Type.Object({ id: Type.String() }); | ||
| const versionParams = Type.Object({ id: Type.String(), versionId: Type.String() }); | ||
|
|
||
| const CreateDraftBody = Type.Object({ | ||
| body: Type.String(), | ||
| parentVersionId: Type.Optional(Type.String()), | ||
| }); | ||
|
|
||
| const UpdateDraftBody = Type.Object({ | ||
| body: Type.Optional(Type.String()), | ||
| documentation: Type.Optional(Type.String()), | ||
| name: Type.Optional(Type.String()), | ||
| notes: Type.Optional(Type.String()), | ||
| }); | ||
|
|
||
| const FinalizeBody = Type.Object({ | ||
| name: Type.Optional(Type.String()), | ||
| notes: Type.Optional(Type.String()), | ||
| wasAutoSaved: Type.Boolean(), | ||
| makeActive: Type.Optional(Type.Boolean()), | ||
| }); | ||
|
|
||
| export function AutomationVersionController({ | ||
| http: { controller }, | ||
| config, | ||
| code_glue, | ||
| }: TServiceParams) { | ||
| controller([config.code_glue.V1, "/automation/:id/versions"], app => | ||
| app | ||
| // GET /api/v1/automation/:id/versions — list all versions for an automation | ||
| .get( | ||
| "/", | ||
| { schema: { params } }, | ||
| ({ params: { id } }) => code_glue.automationVersion.listForAutomation(id), | ||
| ) | ||
| // POST /api/v1/automation/:id/versions — create a draft version | ||
| .post( | ||
| "/", | ||
| { schema: { body: CreateDraftBody, params } }, | ||
| ({ body, params: { id } }) => | ||
| code_glue.automationVersion.createDraft(id, body.body, body.parentVersionId), | ||
| ) | ||
| // PUT /api/v1/automation/:id/versions/:versionId — update draft body or finalize | ||
| .put( | ||
| "/:versionId", | ||
| { schema: { body: UpdateDraftBody, params: versionParams } }, | ||
| ({ body, params: { versionId } }) => | ||
| code_glue.automationVersion.updateDraft(versionId, { | ||
| body: body.body, | ||
| name: body.name, | ||
| notes: body.notes, | ||
| }), | ||
| ) | ||
| // POST /api/v1/automation/:id/versions/:versionId/finalize — finalize a draft | ||
| .post( | ||
| "/:versionId/finalize", | ||
| { schema: { body: FinalizeBody, params: versionParams } }, | ||
| ({ body, params: { versionId } }) => | ||
| code_glue.automationVersion.finalizeVersion(versionId, { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [tsc] <2379> reported by reviewdog 🐶 |
||
| name: body.name, | ||
| notes: body.notes, | ||
| wasAutoSaved: body.wasAutoSaved, | ||
| makeActive: body.makeActive, | ||
| }), | ||
| ) | ||
| // POST /api/v1/automation/:id/versions/:versionId/activate — activate a version | ||
| .post( | ||
| "/:versionId/activate", | ||
| { schema: { params: versionParams } }, | ||
| ({ params: { id, versionId } }) => | ||
| code_glue.automationVersion.activateVersion(id, versionId), | ||
| ) | ||
| // DELETE /api/v1/automation/:id/versions/:versionId — delete a version | ||
| .delete( | ||
| "/:versionId", | ||
| { schema: { params: versionParams } }, | ||
| ({ params: { versionId } }) => | ||
| code_glue.automationVersion.removeVersion(versionId), | ||
| ), | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [tsc] <2379> reported by reviewdog 🐶
Argument of type '{ body: string | undefined; name: string | undefined; notes: string | undefined; }' is not assignable to parameter of type '{ body?: string; name?: string; notes?: string; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'body' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.