diff --git a/Makefile b/Makefile index 3966268..6b2fdc8 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ RELEASE_REMOTE ?= origin VERSION_TAG ?= $(shell git describe --tags --exact-match 2>/dev/null || echo dev) COMMIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) -RELSPEC ?= $(shell command -v relspec 2>/dev/null || echo $(HOME)/go/bin/relspec) +#RELSPEC ?= $(shell command -v relspec 2>/dev/null || echo $(HOME)/go/bin/relspec) +RELSPEC = /home/hein/dev/relspecgo/build/relspec SCHEMA_FILES := $(sort $(wildcard schema/*.dbml)) MERGE_TARGET_TMP := $(CURDIR)/.cache/schema.merge-target.dbml GENERATED_SCHEMA_MIGRATION := migrations/020_generated_schema.sql diff --git a/doc/llm/log/20260505_09.md b/doc/llm/log/20260505_09.md new file mode 100644 index 0000000..7e1d33a --- /dev/null +++ b/doc/llm/log/20260505_09.md @@ -0,0 +1,20 @@ +Completed personas UI reachability and fixed the missing backend ResolveSpec registrations that blocked it. + +- Added Personas navigation/page wiring in the Svelte admin shell. +- Added a personas overview page with tabs for personas, parts, and traits. +- Expanded the persona inspector to load linked parts, traits, skills, guardrails, and arc state. +- Found that `/api/rs/public/agent_parts` and related persona routes were missing because `internal/app/resolvespec_admin.go` manually whitelists ResolveSpec models. +- Registered persona-related ResolveSpec models: `agent_personas`, `agent_parts`, `agent_traits`, persona join tables, arc tables, and `persona_arc`. +- Allowed ResolveSpec mutations for `agent_personas`, `agent_parts`, and `agent_traits`. +- Verified the `internal/app` package still compiles with `env GOCACHE=/tmp/amcs-go-cache go test -run '^$' ./internal/app`. + +Follow-up: + +- Automated ResolveSpec model registration generation with `relspec templ`. +- Added `scripts/templates/resolvespec_models.tmpl`. +- Updated `scripts/generate-models.sh` to generate `internal/app/resolvespec_models_generated.go`. +- Removed the handwritten `resolveSpecModels()` from `internal/app/resolvespec_admin.go`. +- Extended `scripts/patch-generated-models.sh` to fix current relspec output quirks: + - incorrect `persona_arc` primary-key cast + - unused `resolvespec_common` imports in join-table models +- Added focused tests covering persona entity presence and persona mutation allowlisting. diff --git a/doc/llm/log/20260505_11.md b/doc/llm/log/20260505_11.md new file mode 100644 index 0000000..8f6025d --- /dev/null +++ b/doc/llm/log/20260505_11.md @@ -0,0 +1,15 @@ +Fixed the Gitea build break caused by `go:embed` requiring `internal/app/ui/dist` to exist in a clean checkout. + +Changes made: +- Added `internal/app/ui/dist/placeholder.txt` so the embedded UI directory is always present in source control. +- Updated `internal/mcpserver/server_test.go` to derive expected tool names from `BuildToolCatalog()` instead of a stale hard-coded list. +- Removed stale maintenance tool entries from `internal/mcpserver/server.go` because those tools are not currently registered. + +Verification: +- `env GOCACHE=/tmp/go-build go test ./internal/mcpserver -run TestNewListsAllRegisteredTools -v` passes. +- A broader `go test ./internal/app ./cmd/amcs-server` compile check was started, but it did not finish before this log entry was written. + +Migration follow-up: +- Fixed `migrations/020_generated_schema.sql` after PostgreSQL failed with `operator does not exist: name[] = text[]`. +- Root cause: `pg_attribute.attname` is type `name`, so `ARRAY(SELECT a.attname ...)` produced `name[]`, which was compared against `text[]` literals. +- Updated each repeated primary-key introspection block to use `SELECT a.attname::text`, keeping the existing `ARRAY[]::text[]` and `ARRAY['id']` / `ARRAY['persona_id']` comparisons valid. diff --git a/internal/app/resolvespec_admin.go b/internal/app/resolvespec_admin.go index 6d420a0..d0756b2 100644 --- a/internal/app/resolvespec_admin.go +++ b/internal/app/resolvespec_admin.go @@ -9,7 +9,6 @@ import ( "github.com/bitechdev/ResolveSpec/pkg/resolvespec" "github.com/uptrace/bunrouter" - "git.warky.dev/wdevs/amcs/internal/generatedmodels" "git.warky.dev/wdevs/amcs/internal/store" ) @@ -84,6 +83,21 @@ func registerResolveSpecGuards(rs *resolvespec.Handler) { "update": {}, "delete": {}, }, + "agent_personas": { + "create": {}, + "update": {}, + "delete": {}, + }, + "agent_parts": { + "create": {}, + "update": {}, + "delete": {}, + }, + "agent_traits": { + "create": {}, + "update": {}, + "delete": {}, + }, "agent_skills": { "create": {}, "update": {}, @@ -133,40 +147,3 @@ type resolveSpecModel struct { entity string model any } - -func resolveSpecModels() []resolveSpecModel { - //This must be generated with relspec to include all models - //Use the relspec command with template generation. It supprot templ. - return []resolveSpecModel{ - // {schema: "public", entity: "activities", model: generatedmodels.ModelPublicActivities{}}, - {schema: "public", entity: "agent_guardrails", model: generatedmodels.ModelPublicAgentGuardrails{}}, - {schema: "public", entity: "agent_skills", model: generatedmodels.ModelPublicAgentSkills{}}, - {schema: "public", entity: "chat_histories", model: generatedmodels.ModelPublicChatHistories{}}, - // {schema: "public", entity: "contact_interactions", model: generatedmodels.ModelPublicContactInteractions{}}, - {schema: "public", entity: "embeddings", model: generatedmodels.ModelPublicEmbeddings{}}, - // {schema: "public", entity: "family_members", model: generatedmodels.ModelPublicFamilyMembers{}}, - // {schema: "public", entity: "household_items", model: generatedmodels.ModelPublicHouseholdItems{}}, - // {schema: "public", entity: "household_vendors", model: generatedmodels.ModelPublicHouseholdVendors{}}, - // {schema: "public", entity: "important_dates", model: generatedmodels.ModelPublicImportantDates{}}, - {schema: "public", entity: "learnings", model: generatedmodels.ModelPublicLearnings{}}, - // {schema: "public", entity: "maintenance_logs", model: generatedmodels.ModelPublicMaintenanceLogs{}}, - // {schema: "public", entity: "maintenance_tasks", model: generatedmodels.ModelPublicMaintenanceTasks{}}, - // {schema: "public", entity: "meal_plans", model: generatedmodels.ModelPublicMealPlans{}}, - // {schema: "public", entity: "opportunities", model: generatedmodels.ModelPublicOpportunities{}}, - {schema: "public", entity: "plan_dependencies", model: generatedmodels.ModelPublicPlanDependencies{}}, - {schema: "public", entity: "plan_guardrails", model: generatedmodels.ModelPublicPlanGuardrails{}}, - {schema: "public", entity: "plan_related_plans", model: generatedmodels.ModelPublicPlanRelatedPlans{}}, - {schema: "public", entity: "plan_skills", model: generatedmodels.ModelPublicPlanSkills{}}, - {schema: "public", entity: "plans", model: generatedmodels.ModelPublicPlans{}}, - // {schema: "public", entity: "professional_contacts", model: generatedmodels.ModelPublicProfessionalContacts{}}, - {schema: "public", entity: "project_guardrails", model: generatedmodels.ModelPublicProjectGuardrails{}}, - {schema: "public", entity: "project_skills", model: generatedmodels.ModelPublicProjectSkills{}}, - {schema: "public", entity: "projects", model: generatedmodels.ModelPublicProjects{}}, - // {schema: "public", entity: "recipes", model: generatedmodels.ModelPublicRecipes{}}, - // {schema: "public", entity: "shopping_lists", model: generatedmodels.ModelPublicShoppingLists{}}, - {schema: "public", entity: "stored_files", model: generatedmodels.ModelPublicStoredFiles{}}, - {schema: "public", entity: "thought_links", model: generatedmodels.ModelPublicThoughtLinks{}}, - {schema: "public", entity: "thoughts", model: generatedmodels.ModelPublicThoughts{}}, - {schema: "public", entity: "tool_annotations", model: generatedmodels.ModelPublicToolAnnotations{}}, - } -} diff --git a/internal/app/resolvespec_admin_test.go b/internal/app/resolvespec_admin_test.go index 51ad17e..cd32e7d 100644 --- a/internal/app/resolvespec_admin_test.go +++ b/internal/app/resolvespec_admin_test.go @@ -80,6 +80,15 @@ func TestResolveSpecGuardAllowsSupportedMutations(t *testing.T) { {name: "agent_guardrails create", entity: "agent_guardrails", operation: "create"}, {name: "agent_guardrails update", entity: "agent_guardrails", operation: "update"}, {name: "agent_guardrails delete", entity: "agent_guardrails", operation: "delete"}, + {name: "agent_personas create", entity: "agent_personas", operation: "create"}, + {name: "agent_personas update", entity: "agent_personas", operation: "update"}, + {name: "agent_personas delete", entity: "agent_personas", operation: "delete"}, + {name: "agent_parts create", entity: "agent_parts", operation: "create"}, + {name: "agent_parts update", entity: "agent_parts", operation: "update"}, + {name: "agent_parts delete", entity: "agent_parts", operation: "delete"}, + {name: "agent_traits create", entity: "agent_traits", operation: "create"}, + {name: "agent_traits update", entity: "agent_traits", operation: "update"}, + {name: "agent_traits delete", entity: "agent_traits", operation: "delete"}, {name: "stored_files update", entity: "stored_files", operation: "update"}, {name: "stored_files delete", entity: "stored_files", operation: "delete"}, } @@ -171,3 +180,27 @@ func TestResolveSpecModelsIncludeLearnings(t *testing.T) { } t.Fatal("resolveSpecModels() missing public.learnings") } + +func TestResolveSpecModelsIncludePersonaEntities(t *testing.T) { + models := resolveSpecModels() + required := map[string]bool{ + "agent_personas": false, + "agent_parts": false, + "agent_traits": false, + } + + for _, model := range models { + if model.schema != "public" { + continue + } + if _, ok := required[model.entity]; ok { + required[model.entity] = true + } + } + + for entity, found := range required { + if !found { + t.Fatalf("resolveSpecModels() missing public.%s", entity) + } + } +} diff --git a/internal/app/resolvespec_models_generated.go b/internal/app/resolvespec_models_generated.go new file mode 100644 index 0000000..7d83c8f --- /dev/null +++ b/internal/app/resolvespec_models_generated.go @@ -0,0 +1,37 @@ +// Code generated by relspec templ. DO NOT EDIT. +package app + +import "git.warky.dev/wdevs/amcs/internal/generatedmodels" + +func resolveSpecModels() []resolveSpecModel { + return []resolveSpecModel{ + {schema: "public", entity: "agent_guardrails", model: generatedmodels.ModelPublicAgentGuardrails{}}, + {schema: "public", entity: "agent_parts", model: generatedmodels.ModelPublicAgentParts{}}, + {schema: "public", entity: "agent_persona_guardrails", model: generatedmodels.ModelPublicAgentPersonaGuardrails{}}, + {schema: "public", entity: "agent_persona_parts", model: generatedmodels.ModelPublicAgentPersonaParts{}}, + {schema: "public", entity: "agent_persona_skills", model: generatedmodels.ModelPublicAgentPersonaSkills{}}, + {schema: "public", entity: "agent_persona_traits", model: generatedmodels.ModelPublicAgentPersonaTraits{}}, + {schema: "public", entity: "agent_personas", model: generatedmodels.ModelPublicAgentPersonas{}}, + {schema: "public", entity: "agent_skills", model: generatedmodels.ModelPublicAgentSkills{}}, + {schema: "public", entity: "agent_traits", model: generatedmodels.ModelPublicAgentTraits{}}, + {schema: "public", entity: "arc_stage_parts", model: generatedmodels.ModelPublicArcStageParts{}}, + {schema: "public", entity: "arc_stages", model: generatedmodels.ModelPublicArcStages{}}, + {schema: "public", entity: "character_arcs", model: generatedmodels.ModelPublicCharacterArcs{}}, + {schema: "public", entity: "chat_histories", model: generatedmodels.ModelPublicChatHistories{}}, + {schema: "public", entity: "embeddings", model: generatedmodels.ModelPublicEmbeddings{}}, + {schema: "public", entity: "learnings", model: generatedmodels.ModelPublicLearnings{}}, + {schema: "public", entity: "persona_arc", model: generatedmodels.ModelPublicPersonaArc{}}, + {schema: "public", entity: "plan_dependencies", model: generatedmodels.ModelPublicPlanDependencies{}}, + {schema: "public", entity: "plan_guardrails", model: generatedmodels.ModelPublicPlanGuardrails{}}, + {schema: "public", entity: "plan_related_plans", model: generatedmodels.ModelPublicPlanRelatedPlans{}}, + {schema: "public", entity: "plan_skills", model: generatedmodels.ModelPublicPlanSkills{}}, + {schema: "public", entity: "plans", model: generatedmodels.ModelPublicPlans{}}, + {schema: "public", entity: "project_guardrails", model: generatedmodels.ModelPublicProjectGuardrails{}}, + {schema: "public", entity: "project_skills", model: generatedmodels.ModelPublicProjectSkills{}}, + {schema: "public", entity: "projects", model: generatedmodels.ModelPublicProjects{}}, + {schema: "public", entity: "stored_files", model: generatedmodels.ModelPublicStoredFiles{}}, + {schema: "public", entity: "thought_links", model: generatedmodels.ModelPublicThoughtLinks{}}, + {schema: "public", entity: "thoughts", model: generatedmodels.ModelPublicThoughts{}}, + {schema: "public", entity: "tool_annotations", model: generatedmodels.ModelPublicToolAnnotations{}}, + } +} diff --git a/internal/app/ui/dist/placeholder.txt b/internal/app/ui/dist/placeholder.txt new file mode 100644 index 0000000..e8d1a1e --- /dev/null +++ b/internal/app/ui/dist/placeholder.txt @@ -0,0 +1,2 @@ +This placeholder keeps internal/app/ui/dist present in clean source checkouts. +The real UI bundle is generated by the frontend build into this directory. diff --git a/internal/generatedmodels/sql_public_agent_guardrails.go b/internal/generatedmodels/sql_public_agent_guardrails.go deleted file mode 100644 index fb4fb6e..0000000 --- a/internal/generatedmodels/sql_public_agent_guardrails.go +++ /dev/null @@ -1,69 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicAgentGuardrails struct { - bun.BaseModel `bun:"table:public.agent_guardrails,alias:agent_guardrails"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - Content resolvespec_common.SqlString `bun:"content,type:text,notnull," json:"content"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - Severity resolvespec_common.SqlString `bun:"severity,type:text,default:'medium',notnull," json:"severity"` - Tags resolvespec_common.SqlStringArray `bun:"tags,type:text[],default:'{}',notnull," json:"tags"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelGuardrailIDPublicAgentPersonaGuardrails []*ModelPublicAgentPersonaGuardrails `bun:"rel:has-many,join:id=guardrail_id" json:"relguardrailidpublicagentpersonaguardrails,omitempty"` // Has many ModelPublicAgentPersonaGuardrails - RelGuardrailIDPublicPlanGuardrails []*ModelPublicPlanGuardrails `bun:"rel:has-many,join:id=guardrail_id" json:"relguardrailidpublicplanguardrails,omitempty"` // Has many ModelPublicPlanGuardrails - RelGuardrailIDPublicProjectGuardrails []*ModelPublicProjectGuardrails `bun:"rel:has-many,join:id=guardrail_id" json:"relguardrailidpublicprojectguardrails,omitempty"` // Has many ModelPublicProjectGuardrails -} - -// TableName returns the table name for ModelPublicAgentGuardrails -func (m ModelPublicAgentGuardrails) TableName() string { - return "public.agent_guardrails" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentGuardrails -func (m ModelPublicAgentGuardrails) TableNameOnly() string { - return "agent_guardrails" -} - -// SchemaName returns the schema name for ModelPublicAgentGuardrails -func (m ModelPublicAgentGuardrails) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicAgentGuardrails) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicAgentGuardrails) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicAgentGuardrails) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicAgentGuardrails) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicAgentGuardrails) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentGuardrails) GetPrefix() string { - return "AGG" -} diff --git a/internal/generatedmodels/sql_public_agent_parts.go b/internal/generatedmodels/sql_public_agent_parts.go deleted file mode 100644 index c80f299..0000000 --- a/internal/generatedmodels/sql_public_agent_parts.go +++ /dev/null @@ -1,69 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicAgentParts struct { - bun.BaseModel `bun:"table:public.agent_parts,alias:agent_parts"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - Content resolvespec_common.SqlString `bun:"content,type:text,default:'',notnull," json:"content"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - PartType resolvespec_common.SqlString `bun:"part_type,type:text,notnull," json:"part_type"` - Summary resolvespec_common.SqlString `bun:"summary,type:text,notnull," json:"summary"` - Tags resolvespec_common.SqlStringArray `bun:"tags,type:text[],default:'{}',notnull," json:"tags"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelPartIDPublicAgentPersonaParts []*ModelPublicAgentPersonaParts `bun:"rel:has-many,join:id=part_id" json:"relpartidpublicagentpersonaparts,omitempty"` // Has many ModelPublicAgentPersonaParts - RelPartIDPublicArcStageParts []*ModelPublicArcStageParts `bun:"rel:has-many,join:id=part_id" json:"relpartidpublicarcstageparts,omitempty"` // Has many ModelPublicArcStageParts -} - -// TableName returns the table name for ModelPublicAgentParts -func (m ModelPublicAgentParts) TableName() string { - return "public.agent_parts" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentParts -func (m ModelPublicAgentParts) TableNameOnly() string { - return "agent_parts" -} - -// SchemaName returns the schema name for ModelPublicAgentParts -func (m ModelPublicAgentParts) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicAgentParts) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicAgentParts) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicAgentParts) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicAgentParts) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicAgentParts) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentParts) GetPrefix() string { - return "APG" -} diff --git a/internal/generatedmodels/sql_public_agent_persona_guardrails.go b/internal/generatedmodels/sql_public_agent_persona_guardrails.go deleted file mode 100644 index 3b1dd3f..0000000 --- a/internal/generatedmodels/sql_public_agent_persona_guardrails.go +++ /dev/null @@ -1,34 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "github.com/uptrace/bun" -) - -type ModelPublicAgentPersonaGuardrails struct { - bun.BaseModel `bun:"table:public.agent_persona_guardrails,alias:agent_persona_guardrails"` - GuardrailID int64 `bun:"guardrail_id,type:bigint,notnull," json:"guardrail_id"` - PersonaID int64 `bun:"persona_id,type:bigint,notnull," json:"persona_id"` - RelGuardrailID *ModelPublicAgentGuardrails `bun:"rel:has-one,join:guardrail_id=id" json:"relguardrailid,omitempty"` // Has one ModelPublicAgentGuardrails - RelPersonaID *ModelPublicAgentPersonas `bun:"rel:has-one,join:persona_id=id" json:"relpersonaid,omitempty"` // Has one ModelPublicAgentPersonas -} - -// TableName returns the table name for ModelPublicAgentPersonaGuardrails -func (m ModelPublicAgentPersonaGuardrails) TableName() string { - return "public.agent_persona_guardrails" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentPersonaGuardrails -func (m ModelPublicAgentPersonaGuardrails) TableNameOnly() string { - return "agent_persona_guardrails" -} - -// SchemaName returns the schema name for ModelPublicAgentPersonaGuardrails -func (m ModelPublicAgentPersonaGuardrails) SchemaName() string { - return "public" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentPersonaGuardrails) GetPrefix() string { - return "APG" -} diff --git a/internal/generatedmodels/sql_public_agent_persona_parts.go b/internal/generatedmodels/sql_public_agent_persona_parts.go deleted file mode 100644 index 4b09d5a..0000000 --- a/internal/generatedmodels/sql_public_agent_persona_parts.go +++ /dev/null @@ -1,36 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "github.com/uptrace/bun" -) - -type ModelPublicAgentPersonaParts struct { - bun.BaseModel `bun:"table:public.agent_persona_parts,alias:agent_persona_parts"` - PartID int64 `bun:"part_id,type:bigint,notnull," json:"part_id"` - PartOrder int32 `bun:"part_order,type:int,default:0,notnull," json:"part_order"` - PersonaID int64 `bun:"persona_id,type:bigint,notnull," json:"persona_id"` - Priority int32 `bun:"priority,type:int,default:0,notnull," json:"priority"` - RelPartID *ModelPublicAgentParts `bun:"rel:has-one,join:part_id=id" json:"relpartid,omitempty"` // Has one ModelPublicAgentParts - RelPersonaID *ModelPublicAgentPersonas `bun:"rel:has-one,join:persona_id=id" json:"relpersonaid,omitempty"` // Has one ModelPublicAgentPersonas -} - -// TableName returns the table name for ModelPublicAgentPersonaParts -func (m ModelPublicAgentPersonaParts) TableName() string { - return "public.agent_persona_parts" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentPersonaParts -func (m ModelPublicAgentPersonaParts) TableNameOnly() string { - return "agent_persona_parts" -} - -// SchemaName returns the schema name for ModelPublicAgentPersonaParts -func (m ModelPublicAgentPersonaParts) SchemaName() string { - return "public" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentPersonaParts) GetPrefix() string { - return "APP" -} diff --git a/internal/generatedmodels/sql_public_agent_persona_skills.go b/internal/generatedmodels/sql_public_agent_persona_skills.go deleted file mode 100644 index f36e8b0..0000000 --- a/internal/generatedmodels/sql_public_agent_persona_skills.go +++ /dev/null @@ -1,34 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "github.com/uptrace/bun" -) - -type ModelPublicAgentPersonaSkills struct { - bun.BaseModel `bun:"table:public.agent_persona_skills,alias:agent_persona_skills"` - PersonaID int64 `bun:"persona_id,type:bigint,notnull," json:"persona_id"` - SkillID int64 `bun:"skill_id,type:bigint,notnull," json:"skill_id"` - RelPersonaID *ModelPublicAgentPersonas `bun:"rel:has-one,join:persona_id=id" json:"relpersonaid,omitempty"` // Has one ModelPublicAgentPersonas - RelSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:skill_id=id" json:"relskillid,omitempty"` // Has one ModelPublicAgentSkills -} - -// TableName returns the table name for ModelPublicAgentPersonaSkills -func (m ModelPublicAgentPersonaSkills) TableName() string { - return "public.agent_persona_skills" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentPersonaSkills -func (m ModelPublicAgentPersonaSkills) TableNameOnly() string { - return "agent_persona_skills" -} - -// SchemaName returns the schema name for ModelPublicAgentPersonaSkills -func (m ModelPublicAgentPersonaSkills) SchemaName() string { - return "public" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentPersonaSkills) GetPrefix() string { - return "APS" -} diff --git a/internal/generatedmodels/sql_public_agent_persona_traits.go b/internal/generatedmodels/sql_public_agent_persona_traits.go deleted file mode 100644 index 855b459..0000000 --- a/internal/generatedmodels/sql_public_agent_persona_traits.go +++ /dev/null @@ -1,34 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "github.com/uptrace/bun" -) - -type ModelPublicAgentPersonaTraits struct { - bun.BaseModel `bun:"table:public.agent_persona_traits,alias:agent_persona_traits"` - PersonaID int64 `bun:"persona_id,type:bigint,notnull," json:"persona_id"` - TraitID int64 `bun:"trait_id,type:bigint,notnull," json:"trait_id"` - RelPersonaID *ModelPublicAgentPersonas `bun:"rel:has-one,join:persona_id=id" json:"relpersonaid,omitempty"` // Has one ModelPublicAgentPersonas - RelTraitID *ModelPublicAgentTraits `bun:"rel:has-one,join:trait_id=id" json:"reltraitid,omitempty"` // Has one ModelPublicAgentTraits -} - -// TableName returns the table name for ModelPublicAgentPersonaTraits -func (m ModelPublicAgentPersonaTraits) TableName() string { - return "public.agent_persona_traits" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentPersonaTraits -func (m ModelPublicAgentPersonaTraits) TableNameOnly() string { - return "agent_persona_traits" -} - -// SchemaName returns the schema name for ModelPublicAgentPersonaTraits -func (m ModelPublicAgentPersonaTraits) SchemaName() string { - return "public" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentPersonaTraits) GetPrefix() string { - return "APT" -} diff --git a/internal/generatedmodels/sql_public_agent_personas.go b/internal/generatedmodels/sql_public_agent_personas.go deleted file mode 100644 index d792145..0000000 --- a/internal/generatedmodels/sql_public_agent_personas.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicAgentPersonas struct { - bun.BaseModel `bun:"table:public.agent_personas,alias:agent_personas"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CompiledAt resolvespec_common.SqlTimeStamp `bun:"compiled_at,type:timestamptz,nullzero," json:"compiled_at"` - CompiledDetail resolvespec_common.SqlString `bun:"compiled_detail,type:text,default:'',notnull," json:"compiled_detail"` - CompiledSummary resolvespec_common.SqlString `bun:"compiled_summary,type:text,default:'',notnull," json:"compiled_summary"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - Detail resolvespec_common.SqlString `bun:"detail,type:text,default:'',notnull," json:"detail"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - Summary resolvespec_common.SqlString `bun:"summary,type:text,notnull," json:"summary"` - Tags resolvespec_common.SqlStringArray `bun:"tags,type:text[],default:'{}',notnull," json:"tags"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelPersonaIDPublicAgentPersonaParts []*ModelPublicAgentPersonaParts `bun:"rel:has-many,join:id=persona_id" json:"relpersonaidpublicagentpersonaparts,omitempty"` // Has many ModelPublicAgentPersonaParts - RelPersonaIDPublicAgentPersonaSkills []*ModelPublicAgentPersonaSkills `bun:"rel:has-many,join:id=persona_id" json:"relpersonaidpublicagentpersonaskills,omitempty"` // Has many ModelPublicAgentPersonaSkills - RelPersonaIDPublicAgentPersonaGuardrails []*ModelPublicAgentPersonaGuardrails `bun:"rel:has-many,join:id=persona_id" json:"relpersonaidpublicagentpersonaguardrails,omitempty"` // Has many ModelPublicAgentPersonaGuardrails - RelPersonaIDPublicAgentPersonaTraits []*ModelPublicAgentPersonaTraits `bun:"rel:has-many,join:id=persona_id" json:"relpersonaidpublicagentpersonatraits,omitempty"` // Has many ModelPublicAgentPersonaTraits - RelPersonaIDPublicPersonaArcs []*ModelPublicPersonaArc `bun:"rel:has-many,join:id=persona_id" json:"relpersonaidpublicpersonaarcs,omitempty"` // Has many ModelPublicPersonaArc -} - -// TableName returns the table name for ModelPublicAgentPersonas -func (m ModelPublicAgentPersonas) TableName() string { - return "public.agent_personas" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentPersonas -func (m ModelPublicAgentPersonas) TableNameOnly() string { - return "agent_personas" -} - -// SchemaName returns the schema name for ModelPublicAgentPersonas -func (m ModelPublicAgentPersonas) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicAgentPersonas) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicAgentPersonas) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicAgentPersonas) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicAgentPersonas) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicAgentPersonas) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentPersonas) GetPrefix() string { - return "APG" -} diff --git a/internal/generatedmodels/sql_public_agent_skills.go b/internal/generatedmodels/sql_public_agent_skills.go deleted file mode 100644 index b48b505..0000000 --- a/internal/generatedmodels/sql_public_agent_skills.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicAgentSkills struct { - bun.BaseModel `bun:"table:public.agent_skills,alias:agent_skills"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - Content resolvespec_common.SqlString `bun:"content,type:text,notnull," json:"content"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - DomainTags resolvespec_common.SqlStringArray `bun:"domain_tags,type:text[],default:'{}',notnull," json:"domain_tags"` - FrameworkTags resolvespec_common.SqlStringArray `bun:"framework_tags,type:text[],default:'{}',notnull," json:"framework_tags"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - LanguageTags resolvespec_common.SqlStringArray `bun:"language_tags,type:text[],default:'{}',notnull," json:"language_tags"` - LibraryTags resolvespec_common.SqlStringArray `bun:"library_tags,type:text[],default:'{}',notnull," json:"library_tags"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - Tags resolvespec_common.SqlStringArray `bun:"tags,type:text[],default:'{}',notnull," json:"tags"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelSkillIDPublicAgentPersonaSkills []*ModelPublicAgentPersonaSkills `bun:"rel:has-many,join:id=skill_id" json:"relskillidpublicagentpersonaskills,omitempty"` // Has many ModelPublicAgentPersonaSkills - RelRelatedSkillIDPublicLearnings []*ModelPublicLearnings `bun:"rel:has-many,join:id=related_skill_id" json:"relrelatedskillidpubliclearnings,omitempty"` // Has many ModelPublicLearnings - RelSkillIDPublicPlanSkills []*ModelPublicPlanSkills `bun:"rel:has-many,join:id=skill_id" json:"relskillidpublicplanskills,omitempty"` // Has many ModelPublicPlanSkills - RelSkillIDPublicProjectSkills []*ModelPublicProjectSkills `bun:"rel:has-many,join:id=skill_id" json:"relskillidpublicprojectskills,omitempty"` // Has many ModelPublicProjectSkills -} - -// TableName returns the table name for ModelPublicAgentSkills -func (m ModelPublicAgentSkills) TableName() string { - return "public.agent_skills" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentSkills -func (m ModelPublicAgentSkills) TableNameOnly() string { - return "agent_skills" -} - -// SchemaName returns the schema name for ModelPublicAgentSkills -func (m ModelPublicAgentSkills) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicAgentSkills) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicAgentSkills) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicAgentSkills) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicAgentSkills) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicAgentSkills) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentSkills) GetPrefix() string { - return "ASG" -} diff --git a/internal/generatedmodels/sql_public_agent_traits.go b/internal/generatedmodels/sql_public_agent_traits.go deleted file mode 100644 index b1e75b6..0000000 --- a/internal/generatedmodels/sql_public_agent_traits.go +++ /dev/null @@ -1,67 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicAgentTraits struct { - bun.BaseModel `bun:"table:public.agent_traits,alias:agent_traits"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Instruction resolvespec_common.SqlString `bun:"instruction,type:text,default:'',notnull," json:"instruction"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - Tags resolvespec_common.SqlStringArray `bun:"tags,type:text[],default:'{}',notnull," json:"tags"` - TraitType resolvespec_common.SqlString `bun:"trait_type,type:text,notnull," json:"trait_type"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelTraitIDPublicAgentPersonaTraits []*ModelPublicAgentPersonaTraits `bun:"rel:has-many,join:id=trait_id" json:"reltraitidpublicagentpersonatraits,omitempty"` // Has many ModelPublicAgentPersonaTraits -} - -// TableName returns the table name for ModelPublicAgentTraits -func (m ModelPublicAgentTraits) TableName() string { - return "public.agent_traits" -} - -// TableNameOnly returns the table name without schema for ModelPublicAgentTraits -func (m ModelPublicAgentTraits) TableNameOnly() string { - return "agent_traits" -} - -// SchemaName returns the schema name for ModelPublicAgentTraits -func (m ModelPublicAgentTraits) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicAgentTraits) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicAgentTraits) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicAgentTraits) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicAgentTraits) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicAgentTraits) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicAgentTraits) GetPrefix() string { - return "ATG" -} diff --git a/internal/generatedmodels/sql_public_arc_stage_parts.go b/internal/generatedmodels/sql_public_arc_stage_parts.go deleted file mode 100644 index 176d07d..0000000 --- a/internal/generatedmodels/sql_public_arc_stage_parts.go +++ /dev/null @@ -1,34 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "github.com/uptrace/bun" -) - -type ModelPublicArcStageParts struct { - bun.BaseModel `bun:"table:public.arc_stage_parts,alias:arc_stage_parts"` - PartID int64 `bun:"part_id,type:bigint,notnull," json:"part_id"` - StageID int64 `bun:"stage_id,type:bigint,notnull," json:"stage_id"` - RelPartID *ModelPublicAgentParts `bun:"rel:has-one,join:part_id=id" json:"relpartid,omitempty"` // Has one ModelPublicAgentParts - RelStageID *ModelPublicArcStages `bun:"rel:has-one,join:stage_id=id" json:"relstageid,omitempty"` // Has one ModelPublicArcStages -} - -// TableName returns the table name for ModelPublicArcStageParts -func (m ModelPublicArcStageParts) TableName() string { - return "public.arc_stage_parts" -} - -// TableNameOnly returns the table name without schema for ModelPublicArcStageParts -func (m ModelPublicArcStageParts) TableNameOnly() string { - return "arc_stage_parts" -} - -// SchemaName returns the schema name for ModelPublicArcStageParts -func (m ModelPublicArcStageParts) SchemaName() string { - return "public" -} - -// GetPrefix returns the table prefix -func (m ModelPublicArcStageParts) GetPrefix() string { - return "ASP" -} diff --git a/internal/generatedmodels/sql_public_arc_stages.go b/internal/generatedmodels/sql_public_arc_stages.go deleted file mode 100644 index 30c58fc..0000000 --- a/internal/generatedmodels/sql_public_arc_stages.go +++ /dev/null @@ -1,67 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicArcStages struct { - bun.BaseModel `bun:"table:public.arc_stages,alias:arc_stages"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - ArcID int64 `bun:"arc_id,type:bigint,notnull," json:"arc_id"` - Condition resolvespec_common.SqlString `bun:"condition,type:text,default:'',notnull," json:"condition"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - StageOrder int32 `bun:"stage_order,type:int,default:0,notnull," json:"stage_order"` - RelArcID *ModelPublicCharacterArcs `bun:"rel:has-one,join:arc_id=id" json:"relarcid,omitempty"` // Has one ModelPublicCharacterArcs - RelStageIDPublicArcStageParts []*ModelPublicArcStageParts `bun:"rel:has-many,join:id=stage_id" json:"relstageidpublicarcstageparts,omitempty"` // Has many ModelPublicArcStageParts - RelCurrentStageIDPublicPersonaArcs []*ModelPublicPersonaArc `bun:"rel:has-many,join:id=current_stage_id" json:"relcurrentstageidpublicpersonaarcs,omitempty"` // Has many ModelPublicPersonaArc -} - -// TableName returns the table name for ModelPublicArcStages -func (m ModelPublicArcStages) TableName() string { - return "public.arc_stages" -} - -// TableNameOnly returns the table name without schema for ModelPublicArcStages -func (m ModelPublicArcStages) TableNameOnly() string { - return "arc_stages" -} - -// SchemaName returns the schema name for ModelPublicArcStages -func (m ModelPublicArcStages) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicArcStages) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicArcStages) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicArcStages) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicArcStages) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicArcStages) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicArcStages) GetPrefix() string { - return "ASR" -} diff --git a/internal/generatedmodels/sql_public_character_arcs.go b/internal/generatedmodels/sql_public_character_arcs.go deleted file mode 100644 index c7d194d..0000000 --- a/internal/generatedmodels/sql_public_character_arcs.go +++ /dev/null @@ -1,65 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicCharacterArcs struct { - bun.BaseModel `bun:"table:public.character_arcs,alias:character_arcs"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - Summary resolvespec_common.SqlString `bun:"summary,type:text,default:'',notnull," json:"summary"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelArcIDPublicArcStages []*ModelPublicArcStages `bun:"rel:has-many,join:id=arc_id" json:"relarcidpublicarcstages,omitempty"` // Has many ModelPublicArcStages - RelArcIDPublicPersonaArcs []*ModelPublicPersonaArc `bun:"rel:has-many,join:id=arc_id" json:"relarcidpublicpersonaarcs,omitempty"` // Has many ModelPublicPersonaArc -} - -// TableName returns the table name for ModelPublicCharacterArcs -func (m ModelPublicCharacterArcs) TableName() string { - return "public.character_arcs" -} - -// TableNameOnly returns the table name without schema for ModelPublicCharacterArcs -func (m ModelPublicCharacterArcs) TableNameOnly() string { - return "character_arcs" -} - -// SchemaName returns the schema name for ModelPublicCharacterArcs -func (m ModelPublicCharacterArcs) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicCharacterArcs) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicCharacterArcs) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicCharacterArcs) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicCharacterArcs) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicCharacterArcs) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicCharacterArcs) GetPrefix() string { - return "CAH" -} diff --git a/internal/generatedmodels/sql_public_chat_histories.go b/internal/generatedmodels/sql_public_chat_histories.go deleted file mode 100644 index 22b823c..0000000 --- a/internal/generatedmodels/sql_public_chat_histories.go +++ /dev/null @@ -1,70 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicChatHistories struct { - bun.BaseModel `bun:"table:public.chat_histories,alias:chat_histories"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - AgentID resolvespec_common.SqlString `bun:"agent_id,type:text,nullzero," json:"agent_id"` - Channel resolvespec_common.SqlString `bun:"channel,type:text,nullzero," json:"channel"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Messages resolvespec_common.SqlJSONB `bun:"messages,type:jsonb,default:'[]',notnull," json:"messages"` - Metadata resolvespec_common.SqlJSONB `bun:"metadata,type:jsonb,default:'{}',notnull," json:"metadata"` - ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` - SessionID resolvespec_common.SqlString `bun:"session_id,type:text,notnull," json:"session_id"` - Summary resolvespec_common.SqlString `bun:"summary,type:text,nullzero," json:"summary"` - Title resolvespec_common.SqlString `bun:"title,type:text,nullzero," json:"title"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects -} - -// TableName returns the table name for ModelPublicChatHistories -func (m ModelPublicChatHistories) TableName() string { - return "public.chat_histories" -} - -// TableNameOnly returns the table name without schema for ModelPublicChatHistories -func (m ModelPublicChatHistories) TableNameOnly() string { - return "chat_histories" -} - -// SchemaName returns the schema name for ModelPublicChatHistories -func (m ModelPublicChatHistories) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicChatHistories) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicChatHistories) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicChatHistories) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicChatHistories) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicChatHistories) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicChatHistories) GetPrefix() string { - return "CHH" -} diff --git a/internal/generatedmodels/sql_public_embeddings.go b/internal/generatedmodels/sql_public_embeddings.go deleted file mode 100644 index 92d34f5..0000000 --- a/internal/generatedmodels/sql_public_embeddings.go +++ /dev/null @@ -1,66 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicEmbeddings struct { - bun.BaseModel `bun:"table:public.embeddings,alias:embeddings"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),nullzero," json:"created_at"` - Dim int32 `bun:"dim,type:int,notnull," json:"dim"` - Embedding resolvespec_common.SqlVector `bun:"embedding,type:vector,notnull," json:"embedding"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Model resolvespec_common.SqlString `bun:"model,type:text,notnull,unique:uidx_embeddings_thought_id_model," json:"model"` - ThoughtID int64 `bun:"thought_id,type:bigint,notnull,unique:uidx_embeddings_thought_id_model," json:"thought_id"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),nullzero," json:"updated_at"` - RelThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:thought_id=id" json:"relthoughtid,omitempty"` // Has one ModelPublicThoughts -} - -// TableName returns the table name for ModelPublicEmbeddings -func (m ModelPublicEmbeddings) TableName() string { - return "public.embeddings" -} - -// TableNameOnly returns the table name without schema for ModelPublicEmbeddings -func (m ModelPublicEmbeddings) TableNameOnly() string { - return "embeddings" -} - -// SchemaName returns the schema name for ModelPublicEmbeddings -func (m ModelPublicEmbeddings) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicEmbeddings) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicEmbeddings) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicEmbeddings) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicEmbeddings) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicEmbeddings) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicEmbeddings) GetPrefix() string { - return "EMB" -} diff --git a/internal/generatedmodels/sql_public_learnings.go b/internal/generatedmodels/sql_public_learnings.go deleted file mode 100644 index 79b4e81..0000000 --- a/internal/generatedmodels/sql_public_learnings.go +++ /dev/null @@ -1,84 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicLearnings struct { - bun.BaseModel `bun:"table:public.learnings,alias:learnings"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - ActionRequired bool `bun:"action_required,type:boolean,default:false,notnull," json:"action_required"` - Area resolvespec_common.SqlString `bun:"area,type:text,default:'other',notnull," json:"area"` - Category resolvespec_common.SqlString `bun:"category,type:text,default:'insight',notnull," json:"category"` - Confidence resolvespec_common.SqlString `bun:"confidence,type:text,default:'hypothesis',notnull," json:"confidence"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Details resolvespec_common.SqlString `bun:"details,type:text,default:'',notnull," json:"details"` - DuplicateOfLearningID resolvespec_common.SqlInt64 `bun:"duplicate_of_learning_id,type:bigint,nullzero," json:"duplicate_of_learning_id"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Priority resolvespec_common.SqlString `bun:"priority,type:text,default:'medium',notnull," json:"priority"` - ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` - RelatedSkillID resolvespec_common.SqlInt64 `bun:"related_skill_id,type:bigint,nullzero," json:"related_skill_id"` - RelatedThoughtID resolvespec_common.SqlInt64 `bun:"related_thought_id,type:bigint,nullzero," json:"related_thought_id"` - ReviewedAt resolvespec_common.SqlTimeStamp `bun:"reviewed_at,type:timestamptz,nullzero," json:"reviewed_at"` - ReviewedBy resolvespec_common.SqlString `bun:"reviewed_by,type:text,nullzero," json:"reviewed_by"` - SourceRef resolvespec_common.SqlString `bun:"source_ref,type:text,nullzero," json:"source_ref"` - SourceType resolvespec_common.SqlString `bun:"source_type,type:text,nullzero," json:"source_type"` - Status resolvespec_common.SqlString `bun:"status,type:text,default:'pending',notnull," json:"status"` - Summary resolvespec_common.SqlString `bun:"summary,type:text,notnull," json:"summary"` - SupersedesLearningID resolvespec_common.SqlInt64 `bun:"supersedes_learning_id,type:bigint,nullzero," json:"supersedes_learning_id"` - Tags resolvespec_common.SqlStringArray `bun:"tags,type:text[],default:'{}',notnull," json:"tags"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelDuplicateOfLearningID *ModelPublicLearnings `bun:"rel:has-one,join:duplicate_of_learning_id=id" json:"relduplicateoflearningid,omitempty"` // Has one ModelPublicLearnings - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelRelatedSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:related_skill_id=id" json:"relrelatedskillid,omitempty"` // Has one ModelPublicAgentSkills - RelRelatedThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:related_thought_id=id" json:"relrelatedthoughtid,omitempty"` // Has one ModelPublicThoughts - RelSupersedesLearningID *ModelPublicLearnings `bun:"rel:has-one,join:supersedes_learning_id=id" json:"relsupersedeslearningid,omitempty"` // Has one ModelPublicLearnings -} - -// TableName returns the table name for ModelPublicLearnings -func (m ModelPublicLearnings) TableName() string { - return "public.learnings" -} - -// TableNameOnly returns the table name without schema for ModelPublicLearnings -func (m ModelPublicLearnings) TableNameOnly() string { - return "learnings" -} - -// SchemaName returns the schema name for ModelPublicLearnings -func (m ModelPublicLearnings) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicLearnings) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicLearnings) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicLearnings) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicLearnings) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicLearnings) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicLearnings) GetPrefix() string { - return "LEA" -} diff --git a/internal/generatedmodels/sql_public_persona_arc.go b/internal/generatedmodels/sql_public_persona_arc.go deleted file mode 100644 index 01f2eaf..0000000 --- a/internal/generatedmodels/sql_public_persona_arc.go +++ /dev/null @@ -1,64 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicPersonaArc struct { - bun.BaseModel `bun:"table:public.persona_arc,alias:persona_arc"` - PersonaID int64 `bun:"persona_id,type:bigint,pk," json:"persona_id"` - ArcID int64 `bun:"arc_id,type:bigint,notnull," json:"arc_id"` - CurrentStageID int64 `bun:"current_stage_id,type:bigint,notnull," json:"current_stage_id"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelArcID *ModelPublicCharacterArcs `bun:"rel:has-one,join:arc_id=id" json:"relarcid,omitempty"` // Has one ModelPublicCharacterArcs - RelCurrentStageID *ModelPublicArcStages `bun:"rel:has-one,join:current_stage_id=id" json:"relcurrentstageid,omitempty"` // Has one ModelPublicArcStages - RelPersonaID *ModelPublicAgentPersonas `bun:"rel:has-one,join:persona_id=id" json:"relpersonaid,omitempty"` // Has one ModelPublicAgentPersonas -} - -// TableName returns the table name for ModelPublicPersonaArc -func (m ModelPublicPersonaArc) TableName() string { - return "public.persona_arc" -} - -// TableNameOnly returns the table name without schema for ModelPublicPersonaArc -func (m ModelPublicPersonaArc) TableNameOnly() string { - return "persona_arc" -} - -// SchemaName returns the schema name for ModelPublicPersonaArc -func (m ModelPublicPersonaArc) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicPersonaArc) GetID() int64 { - return int64(m.PersonaID) -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicPersonaArc) GetIDStr() string { - return fmt.Sprintf("%d", m.PersonaID) -} - -// SetID sets the primary key value -func (m ModelPublicPersonaArc) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicPersonaArc) UpdateID(newid int64) { - m.PersonaID = newid -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicPersonaArc) GetIDName() string { - return "persona_id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicPersonaArc) GetPrefix() string { - return "PAE" -} diff --git a/internal/generatedmodels/sql_public_plan_dependencies.go b/internal/generatedmodels/sql_public_plan_dependencies.go deleted file mode 100644 index 3b23540..0000000 --- a/internal/generatedmodels/sql_public_plan_dependencies.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicPlanDependencies struct { - bun.BaseModel `bun:"table:public.plan_dependencies,alias:plan_dependencies"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - DependsOnPlanID int64 `bun:"depends_on_plan_id,type:bigint,notnull,unique:uidx_plan_dependencies_plan_id_depends_on_plan_id," json:"depends_on_plan_id"` - PlanID int64 `bun:"plan_id,type:bigint,notnull,unique:uidx_plan_dependencies_plan_id_depends_on_plan_id," json:"plan_id"` - RelDependsOnPlanID *ModelPublicPlans `bun:"rel:has-one,join:depends_on_plan_id=id" json:"reldependsonplanid,omitempty"` // Has one ModelPublicPlans - RelPlanID *ModelPublicPlans `bun:"rel:has-one,join:plan_id=id" json:"relplanid,omitempty"` // Has one ModelPublicPlans -} - -// TableName returns the table name for ModelPublicPlanDependencies -func (m ModelPublicPlanDependencies) TableName() string { - return "public.plan_dependencies" -} - -// TableNameOnly returns the table name without schema for ModelPublicPlanDependencies -func (m ModelPublicPlanDependencies) TableNameOnly() string { - return "plan_dependencies" -} - -// SchemaName returns the schema name for ModelPublicPlanDependencies -func (m ModelPublicPlanDependencies) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicPlanDependencies) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicPlanDependencies) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicPlanDependencies) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicPlanDependencies) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicPlanDependencies) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicPlanDependencies) GetPrefix() string { - return "PDL" -} diff --git a/internal/generatedmodels/sql_public_plan_guardrails.go b/internal/generatedmodels/sql_public_plan_guardrails.go deleted file mode 100644 index 680d930..0000000 --- a/internal/generatedmodels/sql_public_plan_guardrails.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicPlanGuardrails struct { - bun.BaseModel `bun:"table:public.plan_guardrails,alias:plan_guardrails"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - GuardrailID int64 `bun:"guardrail_id,type:bigint,notnull,unique:uidx_plan_guardrails_plan_id_guardrail_id," json:"guardrail_id"` - PlanID int64 `bun:"plan_id,type:bigint,notnull,unique:uidx_plan_guardrails_plan_id_guardrail_id," json:"plan_id"` - RelGuardrailID *ModelPublicAgentGuardrails `bun:"rel:has-one,join:guardrail_id=id" json:"relguardrailid,omitempty"` // Has one ModelPublicAgentGuardrails - RelPlanID *ModelPublicPlans `bun:"rel:has-one,join:plan_id=id" json:"relplanid,omitempty"` // Has one ModelPublicPlans -} - -// TableName returns the table name for ModelPublicPlanGuardrails -func (m ModelPublicPlanGuardrails) TableName() string { - return "public.plan_guardrails" -} - -// TableNameOnly returns the table name without schema for ModelPublicPlanGuardrails -func (m ModelPublicPlanGuardrails) TableNameOnly() string { - return "plan_guardrails" -} - -// SchemaName returns the schema name for ModelPublicPlanGuardrails -func (m ModelPublicPlanGuardrails) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicPlanGuardrails) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicPlanGuardrails) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicPlanGuardrails) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicPlanGuardrails) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicPlanGuardrails) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicPlanGuardrails) GetPrefix() string { - return "PGL" -} diff --git a/internal/generatedmodels/sql_public_plan_related_plans.go b/internal/generatedmodels/sql_public_plan_related_plans.go deleted file mode 100644 index 101a686..0000000 --- a/internal/generatedmodels/sql_public_plan_related_plans.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicPlanRelatedPlans struct { - bun.BaseModel `bun:"table:public.plan_related_plans,alias:plan_related_plans"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - PlanAID int64 `bun:"plan_a_id,type:bigint,notnull,unique:uidx_plan_related_plans_plan_a_id_plan_b_id," json:"plan_a_id"` - PlanBID int64 `bun:"plan_b_id,type:bigint,notnull,unique:uidx_plan_related_plans_plan_a_id_plan_b_id," json:"plan_b_id"` - RelPlanAID *ModelPublicPlans `bun:"rel:has-one,join:plan_a_id=id" json:"relplanaid,omitempty"` // Has one ModelPublicPlans - RelPlanBID *ModelPublicPlans `bun:"rel:has-one,join:plan_b_id=id" json:"relplanbid,omitempty"` // Has one ModelPublicPlans -} - -// TableName returns the table name for ModelPublicPlanRelatedPlans -func (m ModelPublicPlanRelatedPlans) TableName() string { - return "public.plan_related_plans" -} - -// TableNameOnly returns the table name without schema for ModelPublicPlanRelatedPlans -func (m ModelPublicPlanRelatedPlans) TableNameOnly() string { - return "plan_related_plans" -} - -// SchemaName returns the schema name for ModelPublicPlanRelatedPlans -func (m ModelPublicPlanRelatedPlans) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicPlanRelatedPlans) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicPlanRelatedPlans) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicPlanRelatedPlans) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicPlanRelatedPlans) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicPlanRelatedPlans) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicPlanRelatedPlans) GetPrefix() string { - return "PRP" -} diff --git a/internal/generatedmodels/sql_public_plan_skills.go b/internal/generatedmodels/sql_public_plan_skills.go deleted file mode 100644 index 62fee56..0000000 --- a/internal/generatedmodels/sql_public_plan_skills.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicPlanSkills struct { - bun.BaseModel `bun:"table:public.plan_skills,alias:plan_skills"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - PlanID int64 `bun:"plan_id,type:bigint,notnull,unique:uidx_plan_skills_plan_id_skill_id," json:"plan_id"` - SkillID int64 `bun:"skill_id,type:bigint,notnull,unique:uidx_plan_skills_plan_id_skill_id," json:"skill_id"` - RelPlanID *ModelPublicPlans `bun:"rel:has-one,join:plan_id=id" json:"relplanid,omitempty"` // Has one ModelPublicPlans - RelSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:skill_id=id" json:"relskillid,omitempty"` // Has one ModelPublicAgentSkills -} - -// TableName returns the table name for ModelPublicPlanSkills -func (m ModelPublicPlanSkills) TableName() string { - return "public.plan_skills" -} - -// TableNameOnly returns the table name without schema for ModelPublicPlanSkills -func (m ModelPublicPlanSkills) TableNameOnly() string { - return "plan_skills" -} - -// SchemaName returns the schema name for ModelPublicPlanSkills -func (m ModelPublicPlanSkills) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicPlanSkills) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicPlanSkills) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicPlanSkills) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicPlanSkills) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicPlanSkills) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicPlanSkills) GetPrefix() string { - return "PSL" -} diff --git a/internal/generatedmodels/sql_public_plans.go b/internal/generatedmodels/sql_public_plans.go deleted file mode 100644 index c14787a..0000000 --- a/internal/generatedmodels/sql_public_plans.go +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicPlans struct { - bun.BaseModel `bun:"table:public.plans,alias:plans"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CompletedAt resolvespec_common.SqlTimeStamp `bun:"completed_at,type:timestamptz,nullzero," json:"completed_at"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,default:'',notnull," json:"description"` - DueDate resolvespec_common.SqlTimeStamp `bun:"due_date,type:timestamptz,nullzero," json:"due_date"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - LastReviewedAt resolvespec_common.SqlTimeStamp `bun:"last_reviewed_at,type:timestamptz,nullzero," json:"last_reviewed_at"` - Owner resolvespec_common.SqlString `bun:"owner,type:text,nullzero," json:"owner"` - Priority resolvespec_common.SqlString `bun:"priority,type:text,default:'medium',notnull," json:"priority"` // low, medium, high, critical - ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` - ReviewedBy resolvespec_common.SqlString `bun:"reviewed_by,type:text,nullzero," json:"reviewed_by"` - Status resolvespec_common.SqlString `bun:"status,type:text,default:'draft',notnull," json:"status"` // draft, active, blocked, completed, cancelled, superseded - SupersedesPlanID resolvespec_common.SqlInt64 `bun:"supersedes_plan_id,type:bigint,nullzero," json:"supersedes_plan_id"` - Tags resolvespec_common.SqlStringArray `bun:"tags,type:text[],default:'{}',notnull," json:"tags"` - Title resolvespec_common.SqlString `bun:"title,type:text,notnull," json:"title"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelSupersedesPlanID *ModelPublicPlans `bun:"rel:has-one,join:supersedes_plan_id=id" json:"relsupersedesplanid,omitempty"` // Has one ModelPublicPlans - RelDependsOnPlanIDPublicPlanDependencies []*ModelPublicPlanDependencies `bun:"rel:has-many,join:id=depends_on_plan_id" json:"reldependsonplanidpublicplandependencies,omitempty"` // Has many ModelPublicPlanDependencies - RelPlanIDPublicPlanDependencies []*ModelPublicPlanDependencies `bun:"rel:has-many,join:id=plan_id" json:"relplanidpublicplandependencies,omitempty"` // Has many ModelPublicPlanDependencies - RelPlanAIDPublicPlanRelatedPlans []*ModelPublicPlanRelatedPlans `bun:"rel:has-many,join:id=plan_a_id" json:"relplanaidpublicplanrelatedplans,omitempty"` // Has many ModelPublicPlanRelatedPlans - RelPlanBIDPublicPlanRelatedPlans []*ModelPublicPlanRelatedPlans `bun:"rel:has-many,join:id=plan_b_id" json:"relplanbidpublicplanrelatedplans,omitempty"` // Has many ModelPublicPlanRelatedPlans - RelPlanIDPublicPlanSkills []*ModelPublicPlanSkills `bun:"rel:has-many,join:id=plan_id" json:"relplanidpublicplanskills,omitempty"` // Has many ModelPublicPlanSkills - RelPlanIDPublicPlanGuardrails []*ModelPublicPlanGuardrails `bun:"rel:has-many,join:id=plan_id" json:"relplanidpublicplanguardrails,omitempty"` // Has many ModelPublicPlanGuardrails -} - -// TableName returns the table name for ModelPublicPlans -func (m ModelPublicPlans) TableName() string { - return "public.plans" -} - -// TableNameOnly returns the table name without schema for ModelPublicPlans -func (m ModelPublicPlans) TableNameOnly() string { - return "plans" -} - -// SchemaName returns the schema name for ModelPublicPlans -func (m ModelPublicPlans) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicPlans) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicPlans) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicPlans) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicPlans) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicPlans) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicPlans) GetPrefix() string { - return "PLA" -} diff --git a/internal/generatedmodels/sql_public_project_guardrails.go b/internal/generatedmodels/sql_public_project_guardrails.go deleted file mode 100644 index 9db3e31..0000000 --- a/internal/generatedmodels/sql_public_project_guardrails.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicProjectGuardrails struct { - bun.BaseModel `bun:"table:public.project_guardrails,alias:project_guardrails"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - GuardrailID int64 `bun:"guardrail_id,type:bigint,notnull," json:"guardrail_id"` - ProjectID int64 `bun:"project_id,type:bigint,notnull," json:"project_id"` - RelGuardrailID *ModelPublicAgentGuardrails `bun:"rel:has-one,join:guardrail_id=id" json:"relguardrailid,omitempty"` // Has one ModelPublicAgentGuardrails - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects -} - -// TableName returns the table name for ModelPublicProjectGuardrails -func (m ModelPublicProjectGuardrails) TableName() string { - return "public.project_guardrails" -} - -// TableNameOnly returns the table name without schema for ModelPublicProjectGuardrails -func (m ModelPublicProjectGuardrails) TableNameOnly() string { - return "project_guardrails" -} - -// SchemaName returns the schema name for ModelPublicProjectGuardrails -func (m ModelPublicProjectGuardrails) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicProjectGuardrails) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicProjectGuardrails) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicProjectGuardrails) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicProjectGuardrails) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicProjectGuardrails) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicProjectGuardrails) GetPrefix() string { - return "PGR" -} diff --git a/internal/generatedmodels/sql_public_project_skills.go b/internal/generatedmodels/sql_public_project_skills.go deleted file mode 100644 index 9eabbbf..0000000 --- a/internal/generatedmodels/sql_public_project_skills.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicProjectSkills struct { - bun.BaseModel `bun:"table:public.project_skills,alias:project_skills"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - ProjectID int64 `bun:"project_id,type:bigint,notnull," json:"project_id"` - SkillID int64 `bun:"skill_id,type:bigint,notnull," json:"skill_id"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelSkillID *ModelPublicAgentSkills `bun:"rel:has-one,join:skill_id=id" json:"relskillid,omitempty"` // Has one ModelPublicAgentSkills -} - -// TableName returns the table name for ModelPublicProjectSkills -func (m ModelPublicProjectSkills) TableName() string { - return "public.project_skills" -} - -// TableNameOnly returns the table name without schema for ModelPublicProjectSkills -func (m ModelPublicProjectSkills) TableNameOnly() string { - return "project_skills" -} - -// SchemaName returns the schema name for ModelPublicProjectSkills -func (m ModelPublicProjectSkills) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicProjectSkills) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicProjectSkills) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicProjectSkills) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicProjectSkills) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicProjectSkills) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicProjectSkills) GetPrefix() string { - return "PSR" -} diff --git a/internal/generatedmodels/sql_public_projects.go b/internal/generatedmodels/sql_public_projects.go deleted file mode 100644 index 0585663..0000000 --- a/internal/generatedmodels/sql_public_projects.go +++ /dev/null @@ -1,71 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicProjects struct { - bun.BaseModel `bun:"table:public.projects,alias:projects"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),nullzero," json:"created_at"` - Description resolvespec_common.SqlString `bun:"description,type:text,nullzero," json:"description"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - LastActiveAt resolvespec_common.SqlTimeStamp `bun:"last_active_at,type:timestamptz,default:now(),nullzero," json:"last_active_at"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - ThoughtCount resolvespec_common.SqlInt64 `bun:"thought_count,scanonly" json:"thought_count"` - RelProjectIDPublicThoughts []*ModelPublicThoughts `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicthoughts,omitempty"` // Has many ModelPublicThoughts - RelProjectIDPublicStoredFiles []*ModelPublicStoredFiles `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicstoredfiles,omitempty"` // Has many ModelPublicStoredFiles - RelProjectIDPublicChatHistories []*ModelPublicChatHistories `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicchathistories,omitempty"` // Has many ModelPublicChatHistories - RelProjectIDPublicLearnings []*ModelPublicLearnings `bun:"rel:has-many,join:id=project_id" json:"relprojectidpubliclearnings,omitempty"` // Has many ModelPublicLearnings - RelProjectIDPublicPlans []*ModelPublicPlans `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicplans,omitempty"` // Has many ModelPublicPlans - RelProjectIDPublicProjectSkills []*ModelPublicProjectSkills `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicprojectskills,omitempty"` // Has many ModelPublicProjectSkills - RelProjectIDPublicProjectGuardrails []*ModelPublicProjectGuardrails `bun:"rel:has-many,join:id=project_id" json:"relprojectidpublicprojectguardrails,omitempty"` // Has many ModelPublicProjectGuardrails -} - -// TableName returns the table name for ModelPublicProjects -func (m ModelPublicProjects) TableName() string { - return "public.projects" -} - -// TableNameOnly returns the table name without schema for ModelPublicProjects -func (m ModelPublicProjects) TableNameOnly() string { - return "projects" -} - -// SchemaName returns the schema name for ModelPublicProjects -func (m ModelPublicProjects) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicProjects) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicProjects) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicProjects) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicProjects) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicProjects) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicProjects) GetPrefix() string { - return "PRO" -} diff --git a/internal/generatedmodels/sql_public_stored_files.go b/internal/generatedmodels/sql_public_stored_files.go deleted file mode 100644 index e6a1422..0000000 --- a/internal/generatedmodels/sql_public_stored_files.go +++ /dev/null @@ -1,72 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicStoredFiles struct { - bun.BaseModel `bun:"table:public.stored_files,alias:stored_files"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - Content []byte `bun:"content,type:bytea,notnull," json:"content"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Encoding resolvespec_common.SqlString `bun:"encoding,type:text,default:'base64',notnull," json:"encoding"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Kind resolvespec_common.SqlString `bun:"kind,type:text,default:'file',notnull," json:"kind"` - MediaType resolvespec_common.SqlString `bun:"media_type,type:text,notnull," json:"media_type"` - Name resolvespec_common.SqlString `bun:"name,type:text,notnull," json:"name"` - ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` - Sha256 resolvespec_common.SqlString `bun:"sha256,type:text,notnull," json:"sha256"` - SizeBytes int64 `bun:"size_bytes,type:bigint,notnull," json:"size_bytes"` - ThoughtID resolvespec_common.SqlInt64 `bun:"thought_id,type:bigint,nullzero," json:"thought_id"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelThoughtID *ModelPublicThoughts `bun:"rel:has-one,join:thought_id=id" json:"relthoughtid,omitempty"` // Has one ModelPublicThoughts -} - -// TableName returns the table name for ModelPublicStoredFiles -func (m ModelPublicStoredFiles) TableName() string { - return "public.stored_files" -} - -// TableNameOnly returns the table name without schema for ModelPublicStoredFiles -func (m ModelPublicStoredFiles) TableNameOnly() string { - return "stored_files" -} - -// SchemaName returns the schema name for ModelPublicStoredFiles -func (m ModelPublicStoredFiles) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicStoredFiles) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicStoredFiles) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicStoredFiles) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicStoredFiles) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicStoredFiles) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicStoredFiles) GetPrefix() string { - return "SFT" -} diff --git a/internal/generatedmodels/sql_public_thought_links.go b/internal/generatedmodels/sql_public_thought_links.go deleted file mode 100644 index a945fc1..0000000 --- a/internal/generatedmodels/sql_public_thought_links.go +++ /dev/null @@ -1,64 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicThoughtLinks struct { - bun.BaseModel `bun:"table:public.thought_links,alias:thought_links"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),nullzero," json:"created_at"` - FromID int64 `bun:"from_id,type:bigint,notnull," json:"from_id"` - Relation resolvespec_common.SqlString `bun:"relation,type:text,notnull," json:"relation"` - ToID int64 `bun:"to_id,type:bigint,notnull," json:"to_id"` - RelFromID *ModelPublicThoughts `bun:"rel:has-one,join:from_id=id" json:"relfromid,omitempty"` // Has one ModelPublicThoughts - RelToID *ModelPublicThoughts `bun:"rel:has-one,join:to_id=id" json:"reltoid,omitempty"` // Has one ModelPublicThoughts -} - -// TableName returns the table name for ModelPublicThoughtLinks -func (m ModelPublicThoughtLinks) TableName() string { - return "public.thought_links" -} - -// TableNameOnly returns the table name without schema for ModelPublicThoughtLinks -func (m ModelPublicThoughtLinks) TableNameOnly() string { - return "thought_links" -} - -// SchemaName returns the schema name for ModelPublicThoughtLinks -func (m ModelPublicThoughtLinks) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicThoughtLinks) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicThoughtLinks) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicThoughtLinks) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicThoughtLinks) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicThoughtLinks) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicThoughtLinks) GetPrefix() string { - return "TLH" -} diff --git a/internal/generatedmodels/sql_public_thoughts.go b/internal/generatedmodels/sql_public_thoughts.go deleted file mode 100644 index 3d81f7c..0000000 --- a/internal/generatedmodels/sql_public_thoughts.go +++ /dev/null @@ -1,71 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicThoughts struct { - bun.BaseModel `bun:"table:public.thoughts,alias:thoughts"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - ArchivedAt resolvespec_common.SqlTimeStamp `bun:"archived_at,type:timestamptz,nullzero," json:"archived_at"` - Content resolvespec_common.SqlString `bun:"content,type:text,notnull," json:"content"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),nullzero," json:"created_at"` - GUID resolvespec_common.SqlUUID `bun:"guid,type:uuid,default:gen_random_uuid(),notnull," json:"guid"` - Metadata resolvespec_common.SqlJSONB `bun:"metadata,type:jsonb,default:{}::jsonb,nullzero," json:"metadata"` - ProjectID resolvespec_common.SqlInt64 `bun:"project_id,type:bigint,nullzero," json:"project_id"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),nullzero," json:"updated_at"` - RelProjectID *ModelPublicProjects `bun:"rel:has-one,join:project_id=id" json:"relprojectid,omitempty"` // Has one ModelPublicProjects - RelFromIDPublicThoughtLinks []*ModelPublicThoughtLinks `bun:"rel:has-many,join:id=from_id" json:"relfromidpublicthoughtlinks,omitempty"` // Has many ModelPublicThoughtLinks - RelToIDPublicThoughtLinks []*ModelPublicThoughtLinks `bun:"rel:has-many,join:id=to_id" json:"reltoidpublicthoughtlinks,omitempty"` // Has many ModelPublicThoughtLinks - RelThoughtIDPublicEmbeddings []*ModelPublicEmbeddings `bun:"rel:has-many,join:id=thought_id" json:"relthoughtidpublicembeddings,omitempty"` // Has many ModelPublicEmbeddings - RelThoughtIDPublicStoredFiles []*ModelPublicStoredFiles `bun:"rel:has-many,join:id=thought_id" json:"relthoughtidpublicstoredfiles,omitempty"` // Has many ModelPublicStoredFiles - RelRelatedThoughtIDPublicLearnings []*ModelPublicLearnings `bun:"rel:has-many,join:id=related_thought_id" json:"relrelatedthoughtidpubliclearnings,omitempty"` // Has many ModelPublicLearnings -} - -// TableName returns the table name for ModelPublicThoughts -func (m ModelPublicThoughts) TableName() string { - return "public.thoughts" -} - -// TableNameOnly returns the table name without schema for ModelPublicThoughts -func (m ModelPublicThoughts) TableNameOnly() string { - return "thoughts" -} - -// SchemaName returns the schema name for ModelPublicThoughts -func (m ModelPublicThoughts) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicThoughts) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicThoughts) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicThoughts) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicThoughts) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicThoughts) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicThoughts) GetPrefix() string { - return "THO" -} diff --git a/internal/generatedmodels/sql_public_tool_annotations.go b/internal/generatedmodels/sql_public_tool_annotations.go deleted file mode 100644 index 0c386ce..0000000 --- a/internal/generatedmodels/sql_public_tool_annotations.go +++ /dev/null @@ -1,62 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package generatedmodels - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicToolAnnotations struct { - bun.BaseModel `bun:"table:public.tool_annotations,alias:tool_annotations"` - ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` - Notes resolvespec_common.SqlString `bun:"notes,type:text,default:'',notnull," json:"notes"` - ToolName resolvespec_common.SqlString `bun:"tool_name,type:text,notnull," json:"tool_name"` - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamptz,default:now(),notnull," json:"updated_at"` -} - -// TableName returns the table name for ModelPublicToolAnnotations -func (m ModelPublicToolAnnotations) TableName() string { - return "public.tool_annotations" -} - -// TableNameOnly returns the table name without schema for ModelPublicToolAnnotations -func (m ModelPublicToolAnnotations) TableNameOnly() string { - return "tool_annotations" -} - -// SchemaName returns the schema name for ModelPublicToolAnnotations -func (m ModelPublicToolAnnotations) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicToolAnnotations) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicToolAnnotations) GetIDStr() string { - return fmt.Sprintf("%v", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicToolAnnotations) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicToolAnnotations) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicToolAnnotations) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicToolAnnotations) GetPrefix() string { - return "TAO" -} diff --git a/internal/mcpserver/server.go b/internal/mcpserver/server.go index a8de9fe..c4d12ed 100644 --- a/internal/mcpserver/server.go +++ b/internal/mcpserver/server.go @@ -748,12 +748,6 @@ func BuildToolCatalog() []tools.ToolEntry { {Name: "reparse_thought_metadata", Description: "Re-extract and normalize metadata for stored thoughts from their content.", Category: "admin"}, {Name: "retry_failed_metadata", Description: "Retry metadata extraction for thoughts still marked pending or failed.", Category: "admin"}, - // maintenance - {Name: "add_maintenance_task", Description: "Create a recurring or one-time home maintenance task.", Category: "maintenance"}, - {Name: "log_maintenance", Description: "Log completed maintenance work; automatically updates the task's next due date.", Category: "maintenance"}, - {Name: "get_upcoming_maintenance", Description: "List maintenance tasks due within the next N days.", Category: "maintenance"}, - {Name: "search_maintenance_history", Description: "Search the maintenance log by task name, category, or date range.", Category: "maintenance"}, - // skills {Name: "add_skill", Description: "Store a reusable agent skill. Supports language_tags, library_tags, framework_tags, and domain_tags for precise retrieval.", Category: "skills"}, {Name: "remove_skill", Description: "Delete an agent skill by id.", Category: "skills"}, diff --git a/internal/mcpserver/server_test.go b/internal/mcpserver/server_test.go index 9e594a6..7c8ebba 100644 --- a/internal/mcpserver/server_test.go +++ b/internal/mcpserver/server_test.go @@ -27,68 +27,10 @@ func TestNewListsAllRegisteredTools(t *testing.T) { } sort.Strings(got) - want := []string{ - "add_guardrail", - "add_learning", - "add_plan_dependency", - "add_plan_guardrail", - "add_plan_skill", - "add_project_guardrail", - "add_project_skill", - "add_related_plan", - "add_skill", - "annotate_tool", - "archive_thought", - "backfill_embeddings", - "capture_thought", - "create_plan", - "create_project", - "delete_chat_history", - "delete_plan", - "delete_thought", - "describe_tools", - "get_active_project", - "get_chat_history", - "get_learning", - "get_plan", - "get_project_context", - "get_thought", - "get_version_info", - "link_thoughts", - "list_chat_histories", - "list_files", - "list_guardrails", - "list_learnings", - "list_plan_guardrails", - "list_plan_skills", - "list_plans", - "list_project_guardrails", - "list_project_skills", - "list_projects", - "list_skills", - "list_thoughts", - "load_file", - "recall_context", - "related_thoughts", - "remove_guardrail", - "remove_plan_dependency", - "remove_plan_guardrail", - "remove_plan_skill", - "remove_project_guardrail", - "remove_project_skill", - "remove_related_plan", - "remove_skill", - "reparse_thought_metadata", - "retry_failed_metadata", - "save_chat_history", - "save_file", - "search_thoughts", - "set_active_project", - "summarize_thoughts", - "thought_stats", - "update_plan", - "update_thought", - "upload_file", + catalog := BuildToolCatalog() + want := make([]string, 0, len(catalog)) + for _, tool := range catalog { + want = append(want, tool.Name) } sort.Strings(want) diff --git a/migrations/020_generated_schema.sql b/migrations/020_generated_schema.sql index 11ea378..0128f85 100644 --- a/migrations/020_generated_schema.sql +++ b/migrations/020_generated_schema.sql @@ -2,6 +2,8 @@ -- Database: database -- Generated by RelSpec +CREATE EXTENSION IF NOT EXISTS pg_trgm; + -- Sequences for schema: public CREATE SEQUENCE IF NOT EXISTS public.identity_agent_personas_id INCREMENT 1 @@ -3050,30 +3052,4647 @@ BEGIN END; $$; +-- Alter column types for schema: public +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'compiled_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN compiled_at TYPE timestamptz USING compiled_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'compiled_detail' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN compiled_detail TYPE text USING compiled_detail::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'compiled_summary' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN compiled_summary TYPE text USING compiled_summary::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'detail' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN detail TYPE text USING detail::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'summary' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN summary TYPE text USING summary::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN tags TYPE text[] USING tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_personas' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_personas + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'content' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN content TYPE text USING content::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'part_type' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN part_type TYPE text USING part_type::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'summary' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN summary TYPE text USING summary::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN tags TYPE text[] USING tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_parts' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_parts + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_parts' + AND a.attname = 'part_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_parts + ALTER COLUMN part_id TYPE bigint USING part_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_parts' + AND a.attname = 'part_order' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['integer']) THEN + ALTER TABLE public.agent_persona_parts + ALTER COLUMN part_order TYPE integer USING part_order::integer; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_parts' + AND a.attname = 'persona_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_parts + ALTER COLUMN persona_id TYPE bigint USING persona_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_parts' + AND a.attname = 'priority' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['integer']) THEN + ALTER TABLE public.agent_persona_parts + ALTER COLUMN priority TYPE integer USING priority::integer; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_skills' + AND a.attname = 'persona_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_skills + ALTER COLUMN persona_id TYPE bigint USING persona_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_skills' + AND a.attname = 'skill_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_skills + ALTER COLUMN skill_id TYPE bigint USING skill_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_guardrails' + AND a.attname = 'guardrail_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_guardrails + ALTER COLUMN guardrail_id TYPE bigint USING guardrail_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_guardrails' + AND a.attname = 'persona_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_guardrails + ALTER COLUMN persona_id TYPE bigint USING persona_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'instruction' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN instruction TYPE text USING instruction::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN tags TYPE text[] USING tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'trait_type' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN trait_type TYPE text USING trait_type::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_traits' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_traits + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_traits' + AND a.attname = 'persona_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_traits + ALTER COLUMN persona_id TYPE bigint USING persona_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_persona_traits' + AND a.attname = 'trait_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_persona_traits + ALTER COLUMN trait_id TYPE bigint USING trait_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'character_arcs' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.character_arcs + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'character_arcs' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.character_arcs + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'character_arcs' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.character_arcs + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'character_arcs' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.character_arcs + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'character_arcs' + AND a.attname = 'summary' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.character_arcs + ALTER COLUMN summary TYPE text USING summary::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'character_arcs' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.character_arcs + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stages' + AND a.attname = 'arc_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.arc_stages + ALTER COLUMN arc_id TYPE bigint USING arc_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stages' + AND a.attname = 'condition' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.arc_stages + ALTER COLUMN condition TYPE text USING condition::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stages' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.arc_stages + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stages' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.arc_stages + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stages' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.arc_stages + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stages' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.arc_stages + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stages' + AND a.attname = 'stage_order' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['integer']) THEN + ALTER TABLE public.arc_stages + ALTER COLUMN stage_order TYPE integer USING stage_order::integer; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stage_parts' + AND a.attname = 'part_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.arc_stage_parts + ALTER COLUMN part_id TYPE bigint USING part_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'arc_stage_parts' + AND a.attname = 'stage_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.arc_stage_parts + ALTER COLUMN stage_id TYPE bigint USING stage_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'persona_arc' + AND a.attname = 'arc_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.persona_arc + ALTER COLUMN arc_id TYPE bigint USING arc_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'persona_arc' + AND a.attname = 'current_stage_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.persona_arc + ALTER COLUMN current_stage_id TYPE bigint USING current_stage_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'persona_arc' + AND a.attname = 'persona_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.persona_arc + ALTER COLUMN persona_id TYPE bigint USING persona_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'persona_arc' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.persona_arc + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'archived_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN archived_at TYPE timestamptz USING archived_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'content' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN content TYPE text USING content::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'metadata' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['jsonb']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN metadata TYPE jsonb USING metadata::jsonb; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'project_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN project_id TYPE bigint USING project_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thoughts' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.thoughts + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'projects' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.projects + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'projects' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.projects + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'projects' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.projects + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'projects' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.projects + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'projects' + AND a.attname = 'last_active_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.projects + ALTER COLUMN last_active_at TYPE timestamptz USING last_active_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'projects' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.projects + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thought_links' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.thought_links + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thought_links' + AND a.attname = 'from_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.thought_links + ALTER COLUMN from_id TYPE bigint USING from_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thought_links' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.thought_links + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thought_links' + AND a.attname = 'relation' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.thought_links + ALTER COLUMN relation TYPE text USING relation::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'thought_links' + AND a.attname = 'to_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.thought_links + ALTER COLUMN to_id TYPE bigint USING to_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'dim' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['integer']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN dim TYPE integer USING dim::integer; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'embedding' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['vector']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN embedding TYPE vector USING embedding::vector; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'model' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN model TYPE text USING model::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'thought_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN thought_id TYPE bigint USING thought_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'embeddings' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.embeddings + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'content' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bytea']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN content TYPE bytea USING content::bytea; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'encoding' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN encoding TYPE text USING encoding::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'kind' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN kind TYPE text USING kind::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'media_type' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN media_type TYPE text USING media_type::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'project_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN project_id TYPE bigint USING project_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'sha256' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN sha256 TYPE text USING sha256::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'size_bytes' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN size_bytes TYPE bigint USING size_bytes::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'thought_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN thought_id TYPE bigint USING thought_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'stored_files' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.stored_files + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'agent_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN agent_id TYPE text USING agent_id::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'channel' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN channel TYPE text USING channel::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'messages' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['jsonb']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN messages TYPE jsonb USING messages::jsonb; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'metadata' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['jsonb']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN metadata TYPE jsonb USING metadata::jsonb; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'project_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN project_id TYPE bigint USING project_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'session_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN session_id TYPE text USING session_id::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'summary' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN summary TYPE text USING summary::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'title' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN title TYPE text USING title::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'chat_histories' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.chat_histories + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'tool_annotations' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.tool_annotations + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'tool_annotations' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.tool_annotations + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'tool_annotations' + AND a.attname = 'notes' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.tool_annotations + ALTER COLUMN notes TYPE text USING notes::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'tool_annotations' + AND a.attname = 'tool_name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.tool_annotations + ALTER COLUMN tool_name TYPE text USING tool_name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'tool_annotations' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.tool_annotations + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'action_required' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['boolean']) THEN + ALTER TABLE public.learnings + ALTER COLUMN action_required TYPE boolean USING action_required::boolean; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'area' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN area TYPE text USING area::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'category' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN category TYPE text USING category::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'confidence' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN confidence TYPE text USING confidence::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.learnings + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'details' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN details TYPE text USING details::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'duplicate_of_learning_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.learnings + ALTER COLUMN duplicate_of_learning_id TYPE bigint USING duplicate_of_learning_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.learnings + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.learnings + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'priority' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN priority TYPE text USING priority::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'project_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.learnings + ALTER COLUMN project_id TYPE bigint USING project_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'related_skill_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.learnings + ALTER COLUMN related_skill_id TYPE bigint USING related_skill_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'related_thought_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.learnings + ALTER COLUMN related_thought_id TYPE bigint USING related_thought_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'reviewed_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.learnings + ALTER COLUMN reviewed_at TYPE timestamptz USING reviewed_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'reviewed_by' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN reviewed_by TYPE text USING reviewed_by::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'source_ref' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN source_ref TYPE text USING source_ref::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'source_type' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN source_type TYPE text USING source_type::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'status' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN status TYPE text USING status::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'summary' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.learnings + ALTER COLUMN summary TYPE text USING summary::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'supersedes_learning_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.learnings + ALTER COLUMN supersedes_learning_id TYPE bigint USING supersedes_learning_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.learnings + ALTER COLUMN tags TYPE text[] USING tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'learnings' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.learnings + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'completed_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plans + ALTER COLUMN completed_at TYPE timestamptz USING completed_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plans + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.plans + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'due_date' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plans + ALTER COLUMN due_date TYPE timestamptz USING due_date::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.plans + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plans + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'last_reviewed_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plans + ALTER COLUMN last_reviewed_at TYPE timestamptz USING last_reviewed_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'owner' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.plans + ALTER COLUMN owner TYPE text USING owner::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'priority' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.plans + ALTER COLUMN priority TYPE text USING priority::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'project_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plans + ALTER COLUMN project_id TYPE bigint USING project_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'reviewed_by' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.plans + ALTER COLUMN reviewed_by TYPE text USING reviewed_by::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'status' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.plans + ALTER COLUMN status TYPE text USING status::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'supersedes_plan_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plans + ALTER COLUMN supersedes_plan_id TYPE bigint USING supersedes_plan_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.plans + ALTER COLUMN tags TYPE text[] USING tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'title' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.plans + ALTER COLUMN title TYPE text USING title::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plans' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plans + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_dependencies' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plan_dependencies + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_dependencies' + AND a.attname = 'depends_on_plan_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_dependencies + ALTER COLUMN depends_on_plan_id TYPE bigint USING depends_on_plan_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_dependencies' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_dependencies + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_dependencies' + AND a.attname = 'plan_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_dependencies + ALTER COLUMN plan_id TYPE bigint USING plan_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_related_plans' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plan_related_plans + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_related_plans' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_related_plans + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_related_plans' + AND a.attname = 'plan_a_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_related_plans + ALTER COLUMN plan_a_id TYPE bigint USING plan_a_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_related_plans' + AND a.attname = 'plan_b_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_related_plans + ALTER COLUMN plan_b_id TYPE bigint USING plan_b_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_skills' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plan_skills + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_skills' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_skills + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_skills' + AND a.attname = 'plan_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_skills + ALTER COLUMN plan_id TYPE bigint USING plan_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_skills' + AND a.attname = 'skill_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_skills + ALTER COLUMN skill_id TYPE bigint USING skill_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_guardrails' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.plan_guardrails + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_guardrails' + AND a.attname = 'guardrail_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_guardrails + ALTER COLUMN guardrail_id TYPE bigint USING guardrail_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_guardrails' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_guardrails + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'plan_guardrails' + AND a.attname = 'plan_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.plan_guardrails + ALTER COLUMN plan_id TYPE bigint USING plan_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'content' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN content TYPE text USING content::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'domain_tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN domain_tags TYPE text[] USING domain_tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'framework_tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN framework_tags TYPE text[] USING framework_tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'language_tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN language_tags TYPE text[] USING language_tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'library_tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN library_tags TYPE text[] USING library_tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN tags TYPE text[] USING tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_skills' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_skills + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'content' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN content TYPE text USING content::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'description' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN description TYPE text USING description::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'guid' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['uuid']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN guid TYPE uuid USING guid::uuid; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'name' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN name TYPE text USING name::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'severity' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN severity TYPE text USING severity::text; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'tags' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['text[]']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN tags TYPE text[] USING tags::text[]; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'agent_guardrails' + AND a.attname = 'updated_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.agent_guardrails + ALTER COLUMN updated_at TYPE timestamptz USING updated_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_skills' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.project_skills + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_skills' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.project_skills + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_skills' + AND a.attname = 'project_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.project_skills + ALTER COLUMN project_id TYPE bigint USING project_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_skills' + AND a.attname = 'skill_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.project_skills + ALTER COLUMN skill_id TYPE bigint USING skill_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_guardrails' + AND a.attname = 'created_at' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['timestamptz', 'timestamp with time zone']) THEN + ALTER TABLE public.project_guardrails + ALTER COLUMN created_at TYPE timestamptz USING created_at::timestamptz; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_guardrails' + AND a.attname = 'guardrail_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.project_guardrails + ALTER COLUMN guardrail_id TYPE bigint USING guardrail_id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_guardrails' + AND a.attname = 'id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.project_guardrails + ALTER COLUMN id TYPE bigint USING id::bigint; + END IF; +END; +$$; + +DO $$ +DECLARE + current_type text; +BEGIN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + INTO current_type + FROM pg_attribute a + JOIN pg_class t ON t.oid = a.attrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'public' + AND t.relname = 'project_guardrails' + AND a.attname = 'project_id' + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF current_type IS NOT NULL + AND current_type <> ALL(ARRAY['bigint']) THEN + ALTER TABLE public.project_guardrails + ALTER COLUMN project_id TYPE bigint USING project_id::bigint; + END IF; +END; +$$; + -- Primary keys for schema: public DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_personas' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('agent_personas_pkey', 'public_agent_personas_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'agent_personas' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'agent_personas' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.agent_personas DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('agent_personas_pkey', 'public_agent_personas_pkey') THEN + EXECUTE 'ALTER TABLE public.agent_personas DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_personas' - AND constraint_name = 'pk_public_agent_personas' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('agent_personas_pkey', 'public_agent_personas_pkey')) THEN ALTER TABLE public.agent_personas ADD CONSTRAINT pk_public_agent_personas PRIMARY KEY (id); END IF; END; @@ -3081,27 +7700,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_parts' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('agent_parts_pkey', 'public_agent_parts_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'agent_parts' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'agent_parts' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.agent_parts DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('agent_parts_pkey', 'public_agent_parts_pkey') THEN + EXECUTE 'ALTER TABLE public.agent_parts DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_parts' - AND constraint_name = 'pk_public_agent_parts' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('agent_parts_pkey', 'public_agent_parts_pkey')) THEN ALTER TABLE public.agent_parts ADD CONSTRAINT pk_public_agent_parts PRIMARY KEY (id); END IF; END; @@ -3109,27 +7744,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_traits' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('agent_traits_pkey', 'public_agent_traits_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'agent_traits' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'agent_traits' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.agent_traits DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('agent_traits_pkey', 'public_agent_traits_pkey') THEN + EXECUTE 'ALTER TABLE public.agent_traits DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_traits' - AND constraint_name = 'pk_public_agent_traits' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('agent_traits_pkey', 'public_agent_traits_pkey')) THEN ALTER TABLE public.agent_traits ADD CONSTRAINT pk_public_agent_traits PRIMARY KEY (id); END IF; END; @@ -3137,27 +7788,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'character_arcs' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('character_arcs_pkey', 'public_character_arcs_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'character_arcs' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'character_arcs' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.character_arcs DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('character_arcs_pkey', 'public_character_arcs_pkey') THEN + EXECUTE 'ALTER TABLE public.character_arcs DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'character_arcs' - AND constraint_name = 'pk_public_character_arcs' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('character_arcs_pkey', 'public_character_arcs_pkey')) THEN ALTER TABLE public.character_arcs ADD CONSTRAINT pk_public_character_arcs PRIMARY KEY (id); END IF; END; @@ -3165,27 +7832,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'arc_stages' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('arc_stages_pkey', 'public_arc_stages_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'arc_stages' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'arc_stages' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.arc_stages DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('arc_stages_pkey', 'public_arc_stages_pkey') THEN + EXECUTE 'ALTER TABLE public.arc_stages DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'arc_stages' - AND constraint_name = 'pk_public_arc_stages' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('arc_stages_pkey', 'public_arc_stages_pkey')) THEN ALTER TABLE public.arc_stages ADD CONSTRAINT pk_public_arc_stages PRIMARY KEY (id); END IF; END; @@ -3193,27 +7876,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'persona_arc' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('persona_arc_pkey', 'public_persona_arc_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'persona_arc' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['persona_id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'persona_arc' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.persona_arc DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('persona_arc_pkey', 'public_persona_arc_pkey') THEN + EXECUTE 'ALTER TABLE public.persona_arc DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'persona_arc' - AND constraint_name = 'pk_public_persona_arc' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('persona_arc_pkey', 'public_persona_arc_pkey')) THEN ALTER TABLE public.persona_arc ADD CONSTRAINT pk_public_persona_arc PRIMARY KEY (persona_id); END IF; END; @@ -3221,27 +7920,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'thoughts' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('thoughts_pkey', 'public_thoughts_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'thoughts' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'thoughts' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.thoughts DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('thoughts_pkey', 'public_thoughts_pkey') THEN + EXECUTE 'ALTER TABLE public.thoughts DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'thoughts' - AND constraint_name = 'pk_public_thoughts' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('thoughts_pkey', 'public_thoughts_pkey')) THEN ALTER TABLE public.thoughts ADD CONSTRAINT pk_public_thoughts PRIMARY KEY (id); END IF; END; @@ -3249,27 +7964,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'projects' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('projects_pkey', 'public_projects_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'projects' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'projects' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.projects DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('projects_pkey', 'public_projects_pkey') THEN + EXECUTE 'ALTER TABLE public.projects DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'projects' - AND constraint_name = 'pk_public_projects' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('projects_pkey', 'public_projects_pkey')) THEN ALTER TABLE public.projects ADD CONSTRAINT pk_public_projects PRIMARY KEY (id); END IF; END; @@ -3277,27 +8008,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'thought_links' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('thought_links_pkey', 'public_thought_links_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'thought_links' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'thought_links' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.thought_links DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('thought_links_pkey', 'public_thought_links_pkey') THEN + EXECUTE 'ALTER TABLE public.thought_links DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'thought_links' - AND constraint_name = 'pk_public_thought_links' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('thought_links_pkey', 'public_thought_links_pkey')) THEN ALTER TABLE public.thought_links ADD CONSTRAINT pk_public_thought_links PRIMARY KEY (id); END IF; END; @@ -3305,27 +8052,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'embeddings' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('embeddings_pkey', 'public_embeddings_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'embeddings' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'embeddings' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.embeddings DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('embeddings_pkey', 'public_embeddings_pkey') THEN + EXECUTE 'ALTER TABLE public.embeddings DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'embeddings' - AND constraint_name = 'pk_public_embeddings' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('embeddings_pkey', 'public_embeddings_pkey')) THEN ALTER TABLE public.embeddings ADD CONSTRAINT pk_public_embeddings PRIMARY KEY (id); END IF; END; @@ -3333,27 +8096,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'stored_files' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('stored_files_pkey', 'public_stored_files_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'stored_files' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'stored_files' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.stored_files DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('stored_files_pkey', 'public_stored_files_pkey') THEN + EXECUTE 'ALTER TABLE public.stored_files DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'stored_files' - AND constraint_name = 'pk_public_stored_files' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('stored_files_pkey', 'public_stored_files_pkey')) THEN ALTER TABLE public.stored_files ADD CONSTRAINT pk_public_stored_files PRIMARY KEY (id); END IF; END; @@ -3361,27 +8140,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'chat_histories' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('chat_histories_pkey', 'public_chat_histories_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'chat_histories' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'chat_histories' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.chat_histories DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('chat_histories_pkey', 'public_chat_histories_pkey') THEN + EXECUTE 'ALTER TABLE public.chat_histories DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'chat_histories' - AND constraint_name = 'pk_public_chat_histories' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('chat_histories_pkey', 'public_chat_histories_pkey')) THEN ALTER TABLE public.chat_histories ADD CONSTRAINT pk_public_chat_histories PRIMARY KEY (id); END IF; END; @@ -3389,27 +8184,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'tool_annotations' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('tool_annotations_pkey', 'public_tool_annotations_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'tool_annotations' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'tool_annotations' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.tool_annotations DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('tool_annotations_pkey', 'public_tool_annotations_pkey') THEN + EXECUTE 'ALTER TABLE public.tool_annotations DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'tool_annotations' - AND constraint_name = 'pk_public_tool_annotations' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('tool_annotations_pkey', 'public_tool_annotations_pkey')) THEN ALTER TABLE public.tool_annotations ADD CONSTRAINT pk_public_tool_annotations PRIMARY KEY (id); END IF; END; @@ -3417,27 +8228,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'learnings' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('learnings_pkey', 'public_learnings_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'learnings' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'learnings' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.learnings DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('learnings_pkey', 'public_learnings_pkey') THEN + EXECUTE 'ALTER TABLE public.learnings DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'learnings' - AND constraint_name = 'pk_public_learnings' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('learnings_pkey', 'public_learnings_pkey')) THEN ALTER TABLE public.learnings ADD CONSTRAINT pk_public_learnings PRIMARY KEY (id); END IF; END; @@ -3445,27 +8272,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plans' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('plans_pkey', 'public_plans_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'plans' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'plans' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.plans DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('plans_pkey', 'public_plans_pkey') THEN + EXECUTE 'ALTER TABLE public.plans DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plans' - AND constraint_name = 'pk_public_plans' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('plans_pkey', 'public_plans_pkey')) THEN ALTER TABLE public.plans ADD CONSTRAINT pk_public_plans PRIMARY KEY (id); END IF; END; @@ -3473,27 +8316,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_dependencies' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('plan_dependencies_pkey', 'public_plan_dependencies_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'plan_dependencies' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'plan_dependencies' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.plan_dependencies DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('plan_dependencies_pkey', 'public_plan_dependencies_pkey') THEN + EXECUTE 'ALTER TABLE public.plan_dependencies DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_dependencies' - AND constraint_name = 'pk_public_plan_dependencies' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('plan_dependencies_pkey', 'public_plan_dependencies_pkey')) THEN ALTER TABLE public.plan_dependencies ADD CONSTRAINT pk_public_plan_dependencies PRIMARY KEY (id); END IF; END; @@ -3501,27 +8360,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_related_plans' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('plan_related_plans_pkey', 'public_plan_related_plans_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'plan_related_plans' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'plan_related_plans' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.plan_related_plans DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('plan_related_plans_pkey', 'public_plan_related_plans_pkey') THEN + EXECUTE 'ALTER TABLE public.plan_related_plans DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_related_plans' - AND constraint_name = 'pk_public_plan_related_plans' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('plan_related_plans_pkey', 'public_plan_related_plans_pkey')) THEN ALTER TABLE public.plan_related_plans ADD CONSTRAINT pk_public_plan_related_plans PRIMARY KEY (id); END IF; END; @@ -3529,27 +8404,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_skills' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('plan_skills_pkey', 'public_plan_skills_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'plan_skills' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'plan_skills' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.plan_skills DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('plan_skills_pkey', 'public_plan_skills_pkey') THEN + EXECUTE 'ALTER TABLE public.plan_skills DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_skills' - AND constraint_name = 'pk_public_plan_skills' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('plan_skills_pkey', 'public_plan_skills_pkey')) THEN ALTER TABLE public.plan_skills ADD CONSTRAINT pk_public_plan_skills PRIMARY KEY (id); END IF; END; @@ -3557,27 +8448,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_guardrails' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('plan_guardrails_pkey', 'public_plan_guardrails_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'plan_guardrails' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'plan_guardrails' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.plan_guardrails DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('plan_guardrails_pkey', 'public_plan_guardrails_pkey') THEN + EXECUTE 'ALTER TABLE public.plan_guardrails DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'plan_guardrails' - AND constraint_name = 'pk_public_plan_guardrails' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('plan_guardrails_pkey', 'public_plan_guardrails_pkey')) THEN ALTER TABLE public.plan_guardrails ADD CONSTRAINT pk_public_plan_guardrails PRIMARY KEY (id); END IF; END; @@ -3585,27 +8492,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_skills' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('agent_skills_pkey', 'public_agent_skills_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'agent_skills' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'agent_skills' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.agent_skills DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('agent_skills_pkey', 'public_agent_skills_pkey') THEN + EXECUTE 'ALTER TABLE public.agent_skills DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_skills' - AND constraint_name = 'pk_public_agent_skills' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('agent_skills_pkey', 'public_agent_skills_pkey')) THEN ALTER TABLE public.agent_skills ADD CONSTRAINT pk_public_agent_skills PRIMARY KEY (id); END IF; END; @@ -3613,27 +8536,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_guardrails' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('agent_guardrails_pkey', 'public_agent_guardrails_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'agent_guardrails' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'agent_guardrails' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.agent_guardrails DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('agent_guardrails_pkey', 'public_agent_guardrails_pkey') THEN + EXECUTE 'ALTER TABLE public.agent_guardrails DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'agent_guardrails' - AND constraint_name = 'pk_public_agent_guardrails' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('agent_guardrails_pkey', 'public_agent_guardrails_pkey')) THEN ALTER TABLE public.agent_guardrails ADD CONSTRAINT pk_public_agent_guardrails PRIMARY KEY (id); END IF; END; @@ -3641,27 +8580,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'project_skills' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('project_skills_pkey', 'public_project_skills_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'project_skills' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'project_skills' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.project_skills DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('project_skills_pkey', 'public_project_skills_pkey') THEN + EXECUTE 'ALTER TABLE public.project_skills DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'project_skills' - AND constraint_name = 'pk_public_project_skills' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('project_skills_pkey', 'public_project_skills_pkey')) THEN ALTER TABLE public.project_skills ADD CONSTRAINT pk_public_project_skills PRIMARY KEY (id); END IF; END; @@ -3669,27 +8624,43 @@ $$; DO $$ DECLARE - auto_pk_name text; + current_pk_name text; + current_pk_matches boolean := false; BEGIN - -- Drop auto-generated primary key if it exists - SELECT constraint_name INTO auto_pk_name - FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'project_guardrails' - AND constraint_type = 'PRIMARY KEY' - AND constraint_name IN ('project_guardrails_pkey', 'public_project_guardrails_pkey'); + SELECT tc.constraint_name, + COALESCE( + ARRAY( + SELECT a.attname::text + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + JOIN unnest(c.conkey) WITH ORDINALITY AS cols(attnum, ord) + ON TRUE + JOIN pg_attribute a + ON a.attrelid = t.oid + AND a.attnum = cols.attnum + WHERE c.contype = 'p' + AND n.nspname = 'public' + AND t.relname = 'project_guardrails' + ORDER BY cols.ord + ), + ARRAY[]::text[] + ) = ARRAY['id'] + INTO current_pk_name, current_pk_matches + FROM information_schema.table_constraints tc + WHERE tc.table_schema = 'public' + AND tc.table_name = 'project_guardrails' + AND tc.constraint_type = 'PRIMARY KEY'; - IF auto_pk_name IS NOT NULL THEN - EXECUTE 'ALTER TABLE public.project_guardrails DROP CONSTRAINT ' || quote_ident(auto_pk_name); + IF current_pk_name IS NOT NULL + AND NOT current_pk_matches + AND current_pk_name IN ('project_guardrails_pkey', 'public_project_guardrails_pkey') THEN + EXECUTE 'ALTER TABLE public.project_guardrails DROP CONSTRAINT ' || quote_ident(current_pk_name); END IF; - -- Add named primary key if it doesn't exist - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE table_schema = 'public' - AND table_name = 'project_guardrails' - AND constraint_name = 'pk_public_project_guardrails' - ) THEN + -- Add the desired primary key only when no matching primary key already exists. + IF current_pk_name IS NULL + OR (NOT current_pk_matches AND current_pk_name IN ('project_guardrails_pkey', 'public_project_guardrails_pkey')) THEN ALTER TABLE public.project_guardrails ADD CONSTRAINT pk_public_project_guardrails PRIMARY KEY (id); END IF; END; @@ -3724,10 +8695,10 @@ CREATE INDEX IF NOT EXISTS idx_learnings_summary ON public.learnings USING gin (summary gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_learnings_tags - ON public.learnings USING gin (tags); + ON public.learnings USING gin (tags array_ops); CREATE INDEX IF NOT EXISTS idx_plans_tags - ON public.plans USING gin (tags); + ON public.plans USING gin (tags array_ops); CREATE INDEX IF NOT EXISTS idx_plans_title ON public.plans USING gin (title gin_trgm_ops); diff --git a/scripts/generate-models.sh b/scripts/generate-models.sh index 7ff8191..e115e70 100755 --- a/scripts/generate-models.sh +++ b/scripts/generate-models.sh @@ -3,6 +3,8 @@ set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" out_dir="${repo_root}/internal/generatedmodels" +resolve_spec_models_file="${repo_root}/internal/app/resolvespec_models_generated.go" +resolve_spec_template="${repo_root}/scripts/templates/resolvespec_models.tmpl" resolve_relspec() { if [[ -n "${RELSPEC:-}" ]]; then @@ -44,6 +46,12 @@ mkdir -p "${out_dir}" --to-path "${out_dir}" \ --package generatedmodels +"${relspec_bin}" templ \ + --from dbml \ + --from-list "${schema_list}" \ + --template "${resolve_spec_template}" \ + --output "${resolve_spec_models_file}" + # relspec currently emits a few files with unused fmt imports; strip only when fmt is unused. for file in "${out_dir}"/*.go; do sed -i 's/fmt.Sprintf("%d", m.ID)/fmt.Sprintf("%v", m.ID)/g' "${file}" @@ -56,3 +64,4 @@ done bash "${repo_root}/scripts/patch-generated-models.sh" gofmt -w "${out_dir}"/*.go +gofmt -w "${resolve_spec_models_file}" diff --git a/scripts/patch-generated-models.sh b/scripts/patch-generated-models.sh index 060b66a..29bc165 100644 --- a/scripts/patch-generated-models.sh +++ b/scripts/patch-generated-models.sh @@ -4,12 +4,18 @@ set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" models_dir="${repo_root}/internal/generatedmodels" projects_model="${models_dir}/sql_public_projects.go" +persona_arc_model="${models_dir}/sql_public_persona_arc.go" if [[ ! -f "${projects_model}" ]]; then echo "generated projects model not found: ${projects_model}" >&2 exit 1 fi +if [[ ! -f "${persona_arc_model}" ]]; then + echo "generated persona arc model not found: ${persona_arc_model}" >&2 + exit 1 +fi + # Ensure ModelPublicProjects can scan ResolveSpec computed column "thought_count". if ! grep -q "ThoughtCount" "${projects_model}"; then tmp_file="$(mktemp)" @@ -24,3 +30,12 @@ if ! grep -q "ThoughtCount" "${projects_model}"; then mv "${tmp_file}" "${projects_model}" fi +# relspec currently emits an incorrect int32 cast for persona_arc primary key updates. +sed -i 's/m\.PersonaID = int32(newid)/m.PersonaID = newid/' "${persona_arc_model}" + +# Some join-table models import resolvespec_common without using it. +for file in "${models_dir}"/*.go; do + if ! grep -q 'resolvespec_common\.' "${file}"; then + sed -i '/^[[:space:]]*resolvespec_common "github.com\/bitechdev\/ResolveSpec\/pkg\/spectypes"$/d' "${file}" + fi +done diff --git a/scripts/templates/resolvespec_models.tmpl b/scripts/templates/resolvespec_models.tmpl new file mode 100644 index 0000000..386c72d --- /dev/null +++ b/scripts/templates/resolvespec_models.tmpl @@ -0,0 +1,15 @@ +// Code generated by relspec templ. DO NOT EDIT. +package app + +import "git.warky.dev/wdevs/amcs/internal/generatedmodels" + +func resolveSpecModels() []resolveSpecModel { + return []resolveSpecModel{ +{{- range sortBy .Database.Schemas "Name" }} +{{- $schema := .Name }} +{{- range sortBy .Tables "Name" }} + {schema: "{{$schema}}", entity: "{{ .Name }}", model: generatedmodels.Model{{ $schema | toPascalCase }}{{ .Name | toPascalCase }}{}}, +{{- end }} +{{- end }} + } +} diff --git a/ui/src/components/personas/PartsTab.svelte b/ui/src/components/personas/PartsTab.svelte new file mode 100644 index 0000000..fadc9bd --- /dev/null +++ b/ui/src/components/personas/PartsTab.svelte @@ -0,0 +1,351 @@ + + +
+ {#if gridTotal === null}Server-backed grid{:else}{gridTotal} part{gridTotal !== 1 ? 's' : ''}{/if} +
+ +Personas
++ Manage reusable parts and traits alongside the compiled personas they form. Select a persona to inspect its linked components and current arc state. +
++ {#if gridTotal === null}Server-backed grid{:else}{gridTotal} persona{gridTotal !== 1 ? 's' : ''}{/if} +
++ {#if gridTotal === null}Server-backed grid{:else}{gridTotal} trait{gridTotal !== 1 ? 's' : ''}{/if} +
+ +