diff --git a/assets/icon_sm.ico b/assets/icon_sm.ico new file mode 100644 index 0000000..b81ad37 Binary files /dev/null and b/assets/icon_sm.ico differ diff --git a/assets/icon_sm.jpg b/assets/icon_sm.jpg new file mode 100644 index 0000000..e3f6ebd Binary files /dev/null and b/assets/icon_sm.jpg differ diff --git a/assets/icon_sm.png b/assets/icon_sm.png new file mode 100644 index 0000000..dbea137 Binary files /dev/null and b/assets/icon_sm.png differ diff --git a/assets/icon_sm48.png b/assets/icon_sm48.png new file mode 100644 index 0000000..2001352 Binary files /dev/null and b/assets/icon_sm48.png differ diff --git a/internal/app/app.go b/internal/app/app.go index 7b108e4..5c8f1cd 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -100,7 +100,7 @@ func Run(ctx context.Context, configPath string) error { } } authCodes := auth.NewAuthCodeStore() - dynClients := auth.NewDynamicClientStore() + dynClients := auth.NewPostgresClientStore(db.Pool()) activeProjects := session.NewActiveProjects() logger.Info("ai providers initialised", @@ -183,7 +183,7 @@ func Run(ctx context.Context, configPath string) error { } } -func routes(logger *slog.Logger, cfg *config.Config, info buildinfo.Info, db *store.DB, embeddings *ai.EmbeddingRunner, metadata *ai.MetadataRunner, bgEmbeddings *ai.EmbeddingRunner, bgMetadata *ai.MetadataRunner, keyring *auth.Keyring, oauthRegistry *auth.OAuthRegistry, tokenStore *auth.TokenStore, authCodes *auth.AuthCodeStore, dynClients *auth.DynamicClientStore, activeProjects *session.ActiveProjects) (http.Handler, error) { +func routes(logger *slog.Logger, cfg *config.Config, info buildinfo.Info, db *store.DB, embeddings *ai.EmbeddingRunner, metadata *ai.MetadataRunner, bgEmbeddings *ai.EmbeddingRunner, bgMetadata *ai.MetadataRunner, keyring *auth.Keyring, oauthRegistry *auth.OAuthRegistry, tokenStore *auth.TokenStore, authCodes *auth.AuthCodeStore, dynClients auth.ClientStore, activeProjects *session.ActiveProjects) (http.Handler, error) { mux := http.NewServeMux() accessTracker := auth.NewAccessTracker() oauthEnabled := oauthRegistry != nil diff --git a/internal/app/oauth.go b/internal/app/oauth.go index 9dbe787..ec8d995 100644 --- a/internal/app/oauth.go +++ b/internal/app/oauth.go @@ -83,7 +83,7 @@ func oauthMetadataHandler() http.HandlerFunc { // oauthRegisterHandler serves POST /oauth/register per RFC 7591 // (OAuth 2.0 Dynamic Client Registration). -func oauthRegisterHandler(dynClients *auth.DynamicClientStore, log *slog.Logger) http.HandlerFunc { +func oauthRegisterHandler(dynClients auth.ClientStore, log *slog.Logger) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.Header().Set("Allow", http.MethodPost) @@ -130,7 +130,7 @@ func oauthRegisterHandler(dynClients *auth.DynamicClientStore, log *slog.Logger) // oauthAuthorizeHandler serves GET and POST /oauth/authorize. // GET shows an approval page; POST processes the user's approve/deny action. -func oauthAuthorizeHandler(dynClients *auth.DynamicClientStore, authCodes *auth.AuthCodeStore, log *slog.Logger) http.HandlerFunc { +func oauthAuthorizeHandler(dynClients auth.ClientStore, authCodes *auth.AuthCodeStore, log *slog.Logger) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: @@ -144,7 +144,7 @@ func oauthAuthorizeHandler(dynClients *auth.DynamicClientStore, authCodes *auth. } } -func handleAuthorizeGET(w http.ResponseWriter, r *http.Request, dynClients *auth.DynamicClientStore) { +func handleAuthorizeGET(w http.ResponseWriter, r *http.Request, dynClients auth.ClientStore) { q := r.URL.Query() clientID := q.Get("client_id") redirectURI := q.Get("redirect_uri") @@ -178,7 +178,7 @@ func handleAuthorizeGET(w http.ResponseWriter, r *http.Request, dynClients *auth serveAuthorizePage(w, client.ClientName, clientID, redirectURI, state, codeChallenge, codeChallengeMethod, scope) } -func handleAuthorizePOST(w http.ResponseWriter, r *http.Request, dynClients *auth.DynamicClientStore, authCodes *auth.AuthCodeStore, log *slog.Logger) { +func handleAuthorizePOST(w http.ResponseWriter, r *http.Request, dynClients auth.ClientStore, authCodes *auth.AuthCodeStore, log *slog.Logger) { if err := r.ParseForm(); err != nil { http.Error(w, "invalid form", http.StatusBadRequest) return diff --git a/internal/app/resolvespec_models_generated.go b/internal/app/resolvespec_models_generated.go index 7d83c8f..0e06fcf 100644 --- a/internal/app/resolvespec_models_generated.go +++ b/internal/app/resolvespec_models_generated.go @@ -20,6 +20,7 @@ func resolveSpecModels() []resolveSpecModel { {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: "oauth_clients", model: generatedmodels.ModelPublicOauthClients{}}, {schema: "public", entity: "persona_arc", model: generatedmodels.ModelPublicPersonaArc{}}, {schema: "public", entity: "plan_dependencies", model: generatedmodels.ModelPublicPlanDependencies{}}, {schema: "public", entity: "plan_guardrails", model: generatedmodels.ModelPublicPlanGuardrails{}}, diff --git a/internal/auth/dynamic_client_store.go b/internal/auth/dynamic_client_store.go index 1641043..5c3667d 100644 --- a/internal/auth/dynamic_client_store.go +++ b/internal/auth/dynamic_client_store.go @@ -26,6 +26,12 @@ func (c *DynamicClient) HasRedirectURI(uri string) bool { return false } +// ClientStore is the interface implemented by both DynamicClientStore and PostgresClientStore. +type ClientStore interface { + Register(name string, redirectURIs []string) (DynamicClient, error) + Lookup(clientID string) (DynamicClient, bool) +} + // DynamicClientStore holds dynamically registered OAuth clients in memory. type DynamicClientStore struct { mu sync.RWMutex diff --git a/internal/auth/middleware.go b/internal/auth/middleware.go index 8df9368..bccd62a 100644 --- a/internal/auth/middleware.go +++ b/internal/auth/middleware.go @@ -17,6 +17,22 @@ type contextKey string const keyIDContextKey contextKey = "auth.key_id" +// wwwAuthenticate returns the value for a WWW-Authenticate header. +// It advertises Bearer and, when a public URL is known, the OAuth metadata URL per RFC 9728. +func wwwAuthenticate(r *http.Request, publicURL string) string { + base := publicURL + if base == "" { + scheme := "https" + if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" { + scheme = strings.ToLower(proto) + } else if r.TLS == nil { + scheme = "http" + } + base = scheme + "://" + r.Host + } + return `Bearer resource_metadata="` + base + `/.well-known/oauth-authorization-server"` +} + func Middleware(cfg config.AuthConfig, keyring *Keyring, oauthRegistry *OAuthRegistry, tokenStore *TokenStore, tracker *AccessTracker, log *slog.Logger) func(http.Handler) http.Handler { headerName := cfg.HeaderName if headerName == "" { @@ -69,6 +85,7 @@ func Middleware(cfg config.AuthConfig, keyring *Keyring, oauthRegistry *OAuthReg } } log.Warn("bearer token rejected", slog.String("remote_addr", remoteAddr)) + w.Header().Set("WWW-Authenticate", wwwAuthenticate(r, "")+`, error="invalid_token"`) http.Error(w, "invalid token or API key", http.StatusUnauthorized) return } @@ -105,6 +122,7 @@ func Middleware(cfg config.AuthConfig, keyring *Keyring, oauthRegistry *OAuthReg } } + w.Header().Set("WWW-Authenticate", wwwAuthenticate(r, "")) http.Error(w, "authentication required", http.StatusUnauthorized) }) } diff --git a/internal/auth/postgres_client_store.go b/internal/auth/postgres_client_store.go new file mode 100644 index 0000000..40b0b7d --- /dev/null +++ b/internal/auth/postgres_client_store.go @@ -0,0 +1,50 @@ +package auth + +import ( + "context" + "crypto/rand" + "fmt" + + "github.com/jackc/pgx/v5/pgxpool" +) + +// PostgresClientStore persists dynamically registered OAuth clients (RFC 7591) in PostgreSQL. +type PostgresClientStore struct { + pool *pgxpool.Pool +} + +func NewPostgresClientStore(pool *pgxpool.Pool) *PostgresClientStore { + return &PostgresClientStore{pool: pool} +} + +func (s *PostgresClientStore) Register(name string, redirectURIs []string) (DynamicClient, error) { + b := make([]byte, 16) + if _, err := rand.Read(b); err != nil { + return DynamicClient{}, err + } + clientID := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) + + var client DynamicClient + row := s.pool.QueryRow(context.Background(), ` + insert into oauth_clients (client_id, client_name, redirect_uris) + values ($1, $2, $3) + returning client_id, client_name, redirect_uris, created_at + `, clientID, name, redirectURIs) + if err := row.Scan(&client.ClientID, &client.ClientName, &client.RedirectURIs, &client.CreatedAt); err != nil { + return DynamicClient{}, fmt.Errorf("register oauth client: %w", err) + } + return client, nil +} + +func (s *PostgresClientStore) Lookup(clientID string) (DynamicClient, bool) { + var client DynamicClient + row := s.pool.QueryRow(context.Background(), ` + select client_id, client_name, redirect_uris, created_at + from oauth_clients + where client_id = $1 + `, clientID) + if err := row.Scan(&client.ClientID, &client.ClientName, &client.RedirectURIs, &client.CreatedAt); err != nil { + return DynamicClient{}, false + } + return client, true +} diff --git a/internal/generatedmodels/sql_public_agent_persona_guardrails.go b/internal/generatedmodels/sql_public_agent_persona_guardrails.go index 3b1dd3f..314ff12 100644 --- a/internal/generatedmodels/sql_public_agent_persona_guardrails.go +++ b/internal/generatedmodels/sql_public_agent_persona_guardrails.go @@ -2,11 +2,14 @@ package generatedmodels import ( + "fmt" + resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" "github.com/uptrace/bun" ) type ModelPublicAgentPersonaGuardrails struct { bun.BaseModel `bun:"table:public.agent_persona_guardrails,alias:agent_persona_guardrails"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` 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 @@ -28,6 +31,31 @@ func (m ModelPublicAgentPersonaGuardrails) SchemaName() string { return "public" } +// GetID returns the primary key value +func (m ModelPublicAgentPersonaGuardrails) GetID() int64 { + return m.ID.Int64() +} + +// GetIDStr returns the primary key as a string +func (m ModelPublicAgentPersonaGuardrails) GetIDStr() string { + return fmt.Sprintf("%v", m.ID) +} + +// SetID sets the primary key value +func (m ModelPublicAgentPersonaGuardrails) SetID(newid int64) { + m.UpdateID(newid) +} + +// UpdateID updates the primary key value +func (m *ModelPublicAgentPersonaGuardrails) UpdateID(newid int64) { + m.ID.FromString(fmt.Sprintf("%d", newid)) +} + +// GetIDName returns the name of the primary key column +func (m ModelPublicAgentPersonaGuardrails) GetIDName() string { + return "id" +} + // 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 index 4b09d5a..dae158f 100644 --- a/internal/generatedmodels/sql_public_agent_persona_parts.go +++ b/internal/generatedmodels/sql_public_agent_persona_parts.go @@ -2,17 +2,20 @@ package generatedmodels import ( + "fmt" + resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" "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 + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` + 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 @@ -30,6 +33,31 @@ func (m ModelPublicAgentPersonaParts) SchemaName() string { return "public" } +// GetID returns the primary key value +func (m ModelPublicAgentPersonaParts) GetID() int64 { + return m.ID.Int64() +} + +// GetIDStr returns the primary key as a string +func (m ModelPublicAgentPersonaParts) GetIDStr() string { + return fmt.Sprintf("%v", m.ID) +} + +// SetID sets the primary key value +func (m ModelPublicAgentPersonaParts) SetID(newid int64) { + m.UpdateID(newid) +} + +// UpdateID updates the primary key value +func (m *ModelPublicAgentPersonaParts) UpdateID(newid int64) { + m.ID.FromString(fmt.Sprintf("%d", newid)) +} + +// GetIDName returns the name of the primary key column +func (m ModelPublicAgentPersonaParts) GetIDName() string { + return "id" +} + // 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 index f36e8b0..d9d7a49 100644 --- a/internal/generatedmodels/sql_public_agent_persona_skills.go +++ b/internal/generatedmodels/sql_public_agent_persona_skills.go @@ -2,15 +2,18 @@ package generatedmodels import ( + "fmt" + resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" "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 + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` + 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 @@ -28,6 +31,31 @@ func (m ModelPublicAgentPersonaSkills) SchemaName() string { return "public" } +// GetID returns the primary key value +func (m ModelPublicAgentPersonaSkills) GetID() int64 { + return m.ID.Int64() +} + +// GetIDStr returns the primary key as a string +func (m ModelPublicAgentPersonaSkills) GetIDStr() string { + return fmt.Sprintf("%v", m.ID) +} + +// SetID sets the primary key value +func (m ModelPublicAgentPersonaSkills) SetID(newid int64) { + m.UpdateID(newid) +} + +// UpdateID updates the primary key value +func (m *ModelPublicAgentPersonaSkills) UpdateID(newid int64) { + m.ID.FromString(fmt.Sprintf("%d", newid)) +} + +// GetIDName returns the name of the primary key column +func (m ModelPublicAgentPersonaSkills) GetIDName() string { + return "id" +} + // 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 index 855b459..209eb5a 100644 --- a/internal/generatedmodels/sql_public_agent_persona_traits.go +++ b/internal/generatedmodels/sql_public_agent_persona_traits.go @@ -2,15 +2,18 @@ package generatedmodels import ( + "fmt" + resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" "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 + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` + 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 @@ -28,6 +31,31 @@ func (m ModelPublicAgentPersonaTraits) SchemaName() string { return "public" } +// GetID returns the primary key value +func (m ModelPublicAgentPersonaTraits) GetID() int64 { + return m.ID.Int64() +} + +// GetIDStr returns the primary key as a string +func (m ModelPublicAgentPersonaTraits) GetIDStr() string { + return fmt.Sprintf("%v", m.ID) +} + +// SetID sets the primary key value +func (m ModelPublicAgentPersonaTraits) SetID(newid int64) { + m.UpdateID(newid) +} + +// UpdateID updates the primary key value +func (m *ModelPublicAgentPersonaTraits) UpdateID(newid int64) { + m.ID.FromString(fmt.Sprintf("%d", newid)) +} + +// GetIDName returns the name of the primary key column +func (m ModelPublicAgentPersonaTraits) GetIDName() string { + return "id" +} + // GetPrefix returns the table prefix func (m ModelPublicAgentPersonaTraits) GetPrefix() string { return "APT" diff --git a/internal/generatedmodels/sql_public_arc_stage_parts.go b/internal/generatedmodels/sql_public_arc_stage_parts.go index 176d07d..2f488c6 100644 --- a/internal/generatedmodels/sql_public_arc_stage_parts.go +++ b/internal/generatedmodels/sql_public_arc_stage_parts.go @@ -2,15 +2,18 @@ package generatedmodels import ( + "fmt" + resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" "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 + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` + 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 @@ -28,6 +31,31 @@ func (m ModelPublicArcStageParts) SchemaName() string { return "public" } +// GetID returns the primary key value +func (m ModelPublicArcStageParts) GetID() int64 { + return m.ID.Int64() +} + +// GetIDStr returns the primary key as a string +func (m ModelPublicArcStageParts) GetIDStr() string { + return fmt.Sprintf("%v", m.ID) +} + +// SetID sets the primary key value +func (m ModelPublicArcStageParts) SetID(newid int64) { + m.UpdateID(newid) +} + +// UpdateID updates the primary key value +func (m *ModelPublicArcStageParts) UpdateID(newid int64) { + m.ID.FromString(fmt.Sprintf("%d", newid)) +} + +// GetIDName returns the name of the primary key column +func (m ModelPublicArcStageParts) GetIDName() string { + return "id" +} + // GetPrefix returns the table prefix func (m ModelPublicArcStageParts) GetPrefix() string { return "ASP" diff --git a/internal/generatedmodels/sql_public_oauth_clients.go b/internal/generatedmodels/sql_public_oauth_clients.go new file mode 100644 index 0000000..44d7bdf --- /dev/null +++ b/internal/generatedmodels/sql_public_oauth_clients.go @@ -0,0 +1,62 @@ +// Code generated by relspecgo. DO NOT EDIT. +package generatedmodels + +import ( + "fmt" + resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" + "github.com/uptrace/bun" +) + +type ModelPublicOauthClients struct { + bun.BaseModel `bun:"table:public.oauth_clients,alias:oauth_clients"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` + ClientID resolvespec_common.SqlString `bun:"client_id,type:text,notnull," json:"client_id"` + ClientName resolvespec_common.SqlString `bun:"client_name,type:text,default:'',notnull," json:"client_name"` + CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamptz,default:now(),notnull," json:"created_at"` + RedirectUris resolvespec_common.SqlStringArray `bun:"redirect_uris,type:text,default:'{}',notnull," json:"redirect_uris"` +} + +// TableName returns the table name for ModelPublicOauthClients +func (m ModelPublicOauthClients) TableName() string { + return "public.oauth_clients" +} + +// TableNameOnly returns the table name without schema for ModelPublicOauthClients +func (m ModelPublicOauthClients) TableNameOnly() string { + return "oauth_clients" +} + +// SchemaName returns the schema name for ModelPublicOauthClients +func (m ModelPublicOauthClients) SchemaName() string { + return "public" +} + +// GetID returns the primary key value +func (m ModelPublicOauthClients) GetID() int64 { + return m.ID.Int64() +} + +// GetIDStr returns the primary key as a string +func (m ModelPublicOauthClients) GetIDStr() string { + return fmt.Sprintf("%v", m.ID) +} + +// SetID sets the primary key value +func (m ModelPublicOauthClients) SetID(newid int64) { + m.UpdateID(newid) +} + +// UpdateID updates the primary key value +func (m *ModelPublicOauthClients) UpdateID(newid int64) { + m.ID.FromString(fmt.Sprintf("%d", newid)) +} + +// GetIDName returns the name of the primary key column +func (m ModelPublicOauthClients) GetIDName() string { + return "id" +} + +// GetPrefix returns the table prefix +func (m ModelPublicOauthClients) GetPrefix() string { + return "OCA" +} diff --git a/internal/generatedmodels/sql_public_persona_arc.go b/internal/generatedmodels/sql_public_persona_arc.go index 01f2eaf..d0d2343 100644 --- a/internal/generatedmodels/sql_public_persona_arc.go +++ b/internal/generatedmodels/sql_public_persona_arc.go @@ -9,6 +9,7 @@ import ( type ModelPublicPersonaArc struct { bun.BaseModel `bun:"table:public.persona_arc,alias:persona_arc"` + ID resolvespec_common.SqlInt64 `bun:"id,type:bigserial,pk,autoincrement," json:"id"` 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"` @@ -35,12 +36,12 @@ func (m ModelPublicPersonaArc) SchemaName() string { // GetID returns the primary key value func (m ModelPublicPersonaArc) GetID() int64 { - return int64(m.PersonaID) + return m.ID.Int64() } // GetIDStr returns the primary key as a string func (m ModelPublicPersonaArc) GetIDStr() string { - return fmt.Sprintf("%d", m.PersonaID) + return fmt.Sprintf("%v", m.ID) } // SetID sets the primary key value @@ -50,12 +51,12 @@ func (m ModelPublicPersonaArc) SetID(newid int64) { // UpdateID updates the primary key value func (m *ModelPublicPersonaArc) UpdateID(newid int64) { - m.PersonaID = newid + m.ID.FromString(fmt.Sprintf("%d", newid)) } // GetIDName returns the name of the primary key column func (m ModelPublicPersonaArc) GetIDName() string { - return "persona_id" + return "id" } // GetPrefix returns the table prefix diff --git a/internal/store/db.go b/internal/store/db.go index 69e3c43..e6575dc 100644 --- a/internal/store/db.go +++ b/internal/store/db.go @@ -131,3 +131,10 @@ func (db *DB) Bun() *bun.DB { } return db.bun } + +func (db *DB) Pool() *pgxpool.Pool { + if db == nil { + return nil + } + return db.pool +} diff --git a/migrations/020_generated_schema.sql b/migrations/020_generated_schema.sql index 0128f85..da55c3b 100644 --- a/migrations/020_generated_schema.sql +++ b/migrations/020_generated_schema.sql @@ -2,8 +2,6 @@ -- 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 @@ -19,6 +17,27 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_agent_parts_id START 1 CACHE 1; +CREATE SEQUENCE IF NOT EXISTS public.identity_agent_persona_parts_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS public.identity_agent_persona_skills_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS public.identity_agent_persona_guardrails_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + CREATE SEQUENCE IF NOT EXISTS public.identity_agent_traits_id INCREMENT 1 MINVALUE 1 @@ -26,6 +45,13 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_agent_traits_id START 1 CACHE 1; +CREATE SEQUENCE IF NOT EXISTS public.identity_agent_persona_traits_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + CREATE SEQUENCE IF NOT EXISTS public.identity_character_arcs_id INCREMENT 1 MINVALUE 1 @@ -40,7 +66,14 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_arc_stages_id START 1 CACHE 1; -CREATE SEQUENCE IF NOT EXISTS public.identity_persona_arc_persona_id +CREATE SEQUENCE IF NOT EXISTS public.identity_arc_stage_parts_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS public.identity_persona_arc_id INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 @@ -103,6 +136,13 @@ CREATE SEQUENCE IF NOT EXISTS public.identity_learnings_id START 1 CACHE 1; +CREATE SEQUENCE IF NOT EXISTS public.identity_oauth_clients_id + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1 + CACHE 1; + CREATE SEQUENCE IF NOT EXISTS public.identity_plans_id INCREMENT 1 MINVALUE 1 @@ -196,6 +236,7 @@ CREATE TABLE IF NOT EXISTS public.agent_parts ( ); CREATE TABLE IF NOT EXISTS public.agent_persona_parts ( + id bigserial NOT NULL, part_id bigint NOT NULL, part_order integer NOT NULL DEFAULT 0, persona_id bigint NOT NULL, @@ -203,12 +244,14 @@ CREATE TABLE IF NOT EXISTS public.agent_persona_parts ( ); CREATE TABLE IF NOT EXISTS public.agent_persona_skills ( + id bigserial NOT NULL, persona_id bigint NOT NULL, skill_id bigint NOT NULL ); CREATE TABLE IF NOT EXISTS public.agent_persona_guardrails ( guardrail_id bigint NOT NULL, + id bigserial NOT NULL, persona_id bigint NOT NULL ); @@ -225,6 +268,7 @@ CREATE TABLE IF NOT EXISTS public.agent_traits ( ); CREATE TABLE IF NOT EXISTS public.agent_persona_traits ( + id bigserial NOT NULL, persona_id bigint NOT NULL, trait_id bigint NOT NULL ); @@ -249,6 +293,7 @@ CREATE TABLE IF NOT EXISTS public.arc_stages ( ); CREATE TABLE IF NOT EXISTS public.arc_stage_parts ( + id bigserial NOT NULL, part_id bigint NOT NULL, stage_id bigint NOT NULL ); @@ -256,6 +301,7 @@ CREATE TABLE IF NOT EXISTS public.arc_stage_parts ( CREATE TABLE IF NOT EXISTS public.persona_arc ( arc_id bigint NOT NULL, current_stage_id bigint NOT NULL, + id bigserial NOT NULL, persona_id bigint NOT NULL, updated_at timestamptz NOT NULL DEFAULT now() ); @@ -363,6 +409,14 @@ CREATE TABLE IF NOT EXISTS public.learnings ( updated_at timestamptz NOT NULL DEFAULT now() ); +CREATE TABLE IF NOT EXISTS public.oauth_clients ( + client_id text NOT NULL, + client_name text NOT NULL DEFAULT '', + created_at timestamptz NOT NULL DEFAULT now(), + id bigserial NOT NULL, + redirect_uris text[] NOT NULL DEFAULT '{}' +); + CREATE TABLE IF NOT EXISTS public.plans ( completed_at timestamptz, created_at timestamptz NOT NULL DEFAULT now(), @@ -738,6 +792,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'agent_persona_parts' + AND column_name = 'id' + ) THEN + ALTER TABLE public.agent_persona_parts ADD COLUMN id bigserial NOT NULL; + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -790,6 +857,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'agent_persona_skills' + AND column_name = 'id' + ) THEN + ALTER TABLE public.agent_persona_skills ADD COLUMN id bigserial NOT NULL; + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -829,6 +909,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'agent_persona_guardrails' + AND column_name = 'id' + ) THEN + ALTER TABLE public.agent_persona_guardrails ADD COLUMN id bigserial NOT NULL; + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -959,6 +1052,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'agent_persona_traits' + AND column_name = 'id' + ) THEN + ALTER TABLE public.agent_persona_traits ADD COLUMN id bigserial NOT NULL; + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -1154,6 +1260,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'arc_stage_parts' + AND column_name = 'id' + ) THEN + ALTER TABLE public.arc_stage_parts ADD COLUMN id bigserial NOT NULL; + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -1206,6 +1325,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'persona_arc' + AND column_name = 'id' + ) THEN + ALTER TABLE public.persona_arc ADD COLUMN id bigserial NOT NULL; + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -2259,6 +2391,71 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'oauth_clients' + AND column_name = 'client_id' + ) THEN + ALTER TABLE public.oauth_clients ADD COLUMN client_id text NOT NULL; + END IF; +END; +$$; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'oauth_clients' + AND column_name = 'client_name' + ) THEN + ALTER TABLE public.oauth_clients ADD COLUMN client_name text NOT NULL DEFAULT ''; + END IF; +END; +$$; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'oauth_clients' + AND column_name = 'created_at' + ) THEN + ALTER TABLE public.oauth_clients ADD COLUMN created_at timestamptz NOT NULL DEFAULT now(); + END IF; +END; +$$; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'oauth_clients' + AND column_name = 'id' + ) THEN + ALTER TABLE public.oauth_clients ADD COLUMN id bigserial NOT NULL; + END IF; +END; +$$; + +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'oauth_clients' + AND column_name = 'redirect_uris' + ) THEN + ALTER TABLE public.oauth_clients ADD COLUMN redirect_uris text[] NOT NULL DEFAULT '{}'; + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -3052,4647 +3249,30 @@ 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 - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_personas DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.agent_personas ADD CONSTRAINT pk_public_agent_personas PRIMARY KEY (id); END IF; END; @@ -7700,43 +3280,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_parts DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.agent_parts ADD CONSTRAINT pk_public_agent_parts PRIMARY KEY (id); END IF; END; @@ -7744,43 +3308,111 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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_persona_parts' + AND constraint_type = 'PRIMARY KEY' + AND constraint_name IN ('agent_persona_parts_pkey', 'public_agent_persona_parts_pkey'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_persona_parts DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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_persona_parts' + AND constraint_name = 'pk_public_agent_persona_parts' + ) THEN + ALTER TABLE public.agent_persona_parts ADD CONSTRAINT pk_public_agent_persona_parts PRIMARY KEY (id); + END IF; +END; +$$; + +DO $$ +DECLARE + auto_pk_name text; +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_persona_skills' + AND constraint_type = 'PRIMARY KEY' + AND constraint_name IN ('agent_persona_skills_pkey', 'public_agent_persona_skills_pkey'); + + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_persona_skills DROP CONSTRAINT ' || quote_ident(auto_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_persona_skills' + AND constraint_name = 'pk_public_agent_persona_skills' + ) THEN + ALTER TABLE public.agent_persona_skills ADD CONSTRAINT pk_public_agent_persona_skills PRIMARY KEY (id); + END IF; +END; +$$; + +DO $$ +DECLARE + auto_pk_name text; +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_persona_guardrails' + AND constraint_type = 'PRIMARY KEY' + AND constraint_name IN ('agent_persona_guardrails_pkey', 'public_agent_persona_guardrails_pkey'); + + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_persona_guardrails DROP CONSTRAINT ' || quote_ident(auto_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_persona_guardrails' + AND constraint_name = 'pk_public_agent_persona_guardrails' + ) THEN + ALTER TABLE public.agent_persona_guardrails ADD CONSTRAINT pk_public_agent_persona_guardrails PRIMARY KEY (id); + END IF; +END; +$$; + +DO $$ +DECLARE + auto_pk_name text; +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'); + + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_traits DROP CONSTRAINT ' || quote_ident(auto_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 ALTER TABLE public.agent_traits ADD CONSTRAINT pk_public_agent_traits PRIMARY KEY (id); END IF; END; @@ -7788,43 +3420,55 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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_persona_traits' + AND constraint_type = 'PRIMARY KEY' + AND constraint_name IN ('agent_persona_traits_pkey', 'public_agent_persona_traits_pkey'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_persona_traits DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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_persona_traits' + AND constraint_name = 'pk_public_agent_persona_traits' + ) THEN + ALTER TABLE public.agent_persona_traits ADD CONSTRAINT pk_public_agent_persona_traits PRIMARY KEY (id); + END IF; +END; +$$; + +DO $$ +DECLARE + auto_pk_name text; +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'); + + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.character_arcs DROP CONSTRAINT ' || quote_ident(auto_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 ALTER TABLE public.character_arcs ADD CONSTRAINT pk_public_character_arcs PRIMARY KEY (id); END IF; END; @@ -7832,43 +3476,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.arc_stages DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.arc_stages ADD CONSTRAINT pk_public_arc_stages PRIMARY KEY (id); END IF; END; @@ -7876,87 +3504,83 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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_stage_parts' + AND constraint_type = 'PRIMARY KEY' + AND constraint_name IN ('arc_stage_parts_pkey', 'public_arc_stage_parts_pkey'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.arc_stage_parts DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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); + -- 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_stage_parts' + AND constraint_name = 'pk_public_arc_stage_parts' + ) THEN + ALTER TABLE public.arc_stage_parts ADD CONSTRAINT pk_public_arc_stage_parts PRIMARY KEY (id); END IF; END; $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.persona_arc DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 + ALTER TABLE public.persona_arc ADD CONSTRAINT pk_public_persona_arc PRIMARY KEY (id, persona_id); + END IF; +END; +$$; + +DO $$ +DECLARE + auto_pk_name text; +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'); + + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.thoughts DROP CONSTRAINT ' || quote_ident(auto_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 ALTER TABLE public.thoughts ADD CONSTRAINT pk_public_thoughts PRIMARY KEY (id); END IF; END; @@ -7964,43 +3588,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.projects DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.projects ADD CONSTRAINT pk_public_projects PRIMARY KEY (id); END IF; END; @@ -8008,43 +3616,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.thought_links DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.thought_links ADD CONSTRAINT pk_public_thought_links PRIMARY KEY (id); END IF; END; @@ -8052,43 +3644,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.embeddings DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.embeddings ADD CONSTRAINT pk_public_embeddings PRIMARY KEY (id); END IF; END; @@ -8096,43 +3672,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.stored_files DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.stored_files ADD CONSTRAINT pk_public_stored_files PRIMARY KEY (id); END IF; END; @@ -8140,43 +3700,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.chat_histories DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.chat_histories ADD CONSTRAINT pk_public_chat_histories PRIMARY KEY (id); END IF; END; @@ -8184,43 +3728,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.tool_annotations DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.tool_annotations ADD CONSTRAINT pk_public_tool_annotations PRIMARY KEY (id); END IF; END; @@ -8228,43 +3756,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.learnings DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.learnings ADD CONSTRAINT pk_public_learnings PRIMARY KEY (id); END IF; END; @@ -8272,43 +3784,55 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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 = 'oauth_clients' + AND constraint_type = 'PRIMARY KEY' + AND constraint_name IN ('oauth_clients_pkey', 'public_oauth_clients_pkey'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.oauth_clients DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 = 'oauth_clients' + AND constraint_name = 'pk_public_oauth_clients' + ) THEN + ALTER TABLE public.oauth_clients ADD CONSTRAINT pk_public_oauth_clients PRIMARY KEY (id); + END IF; +END; +$$; + +DO $$ +DECLARE + auto_pk_name text; +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'); + + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.plans DROP CONSTRAINT ' || quote_ident(auto_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 ALTER TABLE public.plans ADD CONSTRAINT pk_public_plans PRIMARY KEY (id); END IF; END; @@ -8316,43 +3840,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.plan_dependencies DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.plan_dependencies ADD CONSTRAINT pk_public_plan_dependencies PRIMARY KEY (id); END IF; END; @@ -8360,43 +3868,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.plan_related_plans DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.plan_related_plans ADD CONSTRAINT pk_public_plan_related_plans PRIMARY KEY (id); END IF; END; @@ -8404,43 +3896,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.plan_skills DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.plan_skills ADD CONSTRAINT pk_public_plan_skills PRIMARY KEY (id); END IF; END; @@ -8448,43 +3924,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.plan_guardrails DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.plan_guardrails ADD CONSTRAINT pk_public_plan_guardrails PRIMARY KEY (id); END IF; END; @@ -8492,43 +3952,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_skills DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.agent_skills ADD CONSTRAINT pk_public_agent_skills PRIMARY KEY (id); END IF; END; @@ -8536,43 +3980,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.agent_guardrails DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.agent_guardrails ADD CONSTRAINT pk_public_agent_guardrails PRIMARY KEY (id); END IF; END; @@ -8580,43 +4008,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.project_skills DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.project_skills ADD CONSTRAINT pk_public_project_skills PRIMARY KEY (id); END IF; END; @@ -8624,43 +4036,27 @@ $$; DO $$ DECLARE - current_pk_name text; - current_pk_matches boolean := false; + auto_pk_name text; BEGIN - 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'; + -- 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'); - 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); + IF auto_pk_name IS NOT NULL THEN + EXECUTE 'ALTER TABLE public.project_guardrails DROP CONSTRAINT ' || quote_ident(auto_pk_name); END IF; - -- 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 + -- 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 ALTER TABLE public.project_guardrails ADD CONSTRAINT pk_public_project_guardrails PRIMARY KEY (id); END IF; END; @@ -8673,12 +4069,6 @@ CREATE INDEX IF NOT EXISTS idx_agent_persona_parts_persona_id_part_id CREATE INDEX IF NOT EXISTS idx_agent_persona_skills_persona_id_skill_id ON public.agent_persona_skills USING btree (persona_id, skill_id); -CREATE INDEX IF NOT EXISTS idx_agent_persona_guardrails_persona_id_guardrail_id - ON public.agent_persona_guardrails USING btree (persona_id, guardrail_id); - -CREATE INDEX IF NOT EXISTS idx_agent_persona_traits_persona_id_trait_id - ON public.agent_persona_traits USING btree (persona_id, trait_id); - CREATE INDEX IF NOT EXISTS idx_arc_stage_parts_stage_id_part_id ON public.arc_stage_parts USING btree (stage_id, part_id); @@ -8695,10 +4085,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 array_ops); + ON public.learnings USING gin (tags gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_plans_tags - ON public.plans USING gin (tags array_ops); + ON public.plans USING gin (tags gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_plans_title ON public.plans USING gin (title gin_trgm_ops); @@ -8917,6 +4307,19 @@ BEGIN END; $$; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE table_schema = 'public' + AND table_name = 'oauth_clients' + AND constraint_name = 'ukey_oauth_clients_client_id' + ) THEN + ALTER TABLE public.oauth_clients ADD CONSTRAINT ukey_oauth_clients_client_id UNIQUE (client_id); + END IF; +END; +$$; + DO $$ BEGIN IF NOT EXISTS ( @@ -9664,6 +5067,63 @@ BEGIN END; $$; DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_agent_persona_parts_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.agent_persona_parts + INTO m_cnt; + + PERFORM setval('public.identity_agent_persona_parts_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_agent_persona_skills_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.agent_persona_skills + INTO m_cnt; + + PERFORM setval('public.identity_agent_persona_skills_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_agent_persona_guardrails_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.agent_persona_guardrails + INTO m_cnt; + + PERFORM setval('public.identity_agent_persona_guardrails_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ DECLARE m_cnt bigint; BEGIN @@ -9683,6 +5143,25 @@ BEGIN END; $$; DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_agent_persona_traits_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.agent_persona_traits + INTO m_cnt; + + PERFORM setval('public.identity_agent_persona_traits_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ DECLARE m_cnt bigint; BEGIN @@ -9727,15 +5206,34 @@ BEGIN IF EXISTS ( SELECT 1 FROM pg_class c INNER JOIN pg_namespace n ON n.oid = c.relnamespace - WHERE c.relname = 'identity_persona_arc_persona_id' + WHERE c.relname = 'identity_arc_stage_parts_id' AND n.nspname = 'public' AND c.relkind = 'S' ) THEN - SELECT COALESCE(MAX(persona_id), 0) + 1 + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.arc_stage_parts + INTO m_cnt; + + PERFORM setval('public.identity_arc_stage_parts_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_persona_arc_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 FROM public.persona_arc INTO m_cnt; - PERFORM setval('public.identity_persona_arc_persona_id'::regclass, m_cnt); + PERFORM setval('public.identity_persona_arc_id'::regclass, m_cnt); END IF; END; $$; @@ -9892,6 +5390,25 @@ BEGIN END; $$; DO $$ +DECLARE + m_cnt bigint; +BEGIN + IF EXISTS ( + SELECT 1 FROM pg_class c + INNER JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE c.relname = 'identity_oauth_clients_id' + AND n.nspname = 'public' + AND c.relkind = 'S' + ) THEN + SELECT COALESCE(MAX(id), 0) + 1 + FROM public.oauth_clients + INTO m_cnt; + + PERFORM setval('public.identity_oauth_clients_id'::regclass, m_cnt); + END IF; +END; +$$; +DO $$ DECLARE m_cnt bigint; BEGIN @@ -10089,5 +5606,6 @@ $$; + diff --git a/schema/agent_personas.dbml b/schema/agent_personas.dbml index c433591..b6877ba 100644 --- a/schema/agent_personas.dbml +++ b/schema/agent_personas.dbml @@ -27,33 +27,35 @@ Table agent_parts { } Table agent_persona_parts { + id bigserial [pk] persona_id bigint [not null, ref: > agent_personas.id] part_id bigint [not null, ref: > agent_parts.id] part_order int [not null, default: 0] priority int [not null, default: 0] indexes { - (persona_id, part_id) [pk] + (persona_id, part_id) [uk] persona_id } } Table agent_persona_skills { + id bigserial [pk] persona_id bigint [not null, ref: > agent_personas.id] skill_id bigint [not null, ref: > agent_skills.id] indexes { - (persona_id, skill_id) [pk] + (persona_id, skill_id) [uk] persona_id } } Table agent_persona_guardrails { + id bigserial [pk] persona_id bigint [not null, ref: > agent_personas.id] guardrail_id bigint [not null, ref: > agent_guardrails.id] indexes { - (persona_id, guardrail_id) [pk] persona_id } } @@ -71,11 +73,11 @@ Table agent_traits { } Table agent_persona_traits { + id bigserial [pk] persona_id bigint [not null, ref: > agent_personas.id] trait_id bigint [not null, ref: > agent_traits.id] indexes { - (persona_id, trait_id) [pk] persona_id } } @@ -100,15 +102,17 @@ Table arc_stages { } Table arc_stage_parts { + id bigserial [pk] stage_id bigint [not null, ref: > arc_stages.id] part_id bigint [not null, ref: > agent_parts.id] indexes { - (stage_id, part_id) [pk] + (stage_id, part_id) } } Table persona_arc { + id bigserial [pk] persona_id bigint [pk, ref: > agent_personas.id] arc_id bigint [not null, ref: > character_arcs.id] current_stage_id bigint [not null, ref: > arc_stages.id] diff --git a/schema/oauth_clients.dbml b/schema/oauth_clients.dbml new file mode 100644 index 0000000..37ed7a7 --- /dev/null +++ b/schema/oauth_clients.dbml @@ -0,0 +1,8 @@ +// OAuth 2.0 Dynamic Client Registration (RFC 7591) +Table oauth_clients { + id bigserial [pk] + client_id text [unique, not null] + client_name text [not null, default: ''] + redirect_uris "text[]" [not null, default: `'{}'`] + created_at timestamptz [not null, default: `now()`] +}