diff --git a/backend/controller/cronjobs/dal/internal/sql/models.go b/backend/controller/cronjobs/dal/internal/sql/models.go index aca898349d..ad37c8ab73 100644 --- a/backend/controller/cronjobs/dal/internal/sql/models.go +++ b/backend/controller/cronjobs/dal/internal/sql/models.go @@ -5,359 +5,14 @@ package sql import ( - "database/sql/driver" "encoding/json" - "fmt" "time" - "github.com/TBD54566975/ftl/backend/controller/leases" - "github.com/TBD54566975/ftl/backend/controller/sql/sqltypes" "github.com/TBD54566975/ftl/backend/schema" - "github.com/TBD54566975/ftl/internal/encryption" "github.com/TBD54566975/ftl/internal/model" "github.com/alecthomas/types/optional" - "github.com/google/uuid" - "github.com/sqlc-dev/pqtype" ) -type AsyncCallState string - -const ( - AsyncCallStatePending AsyncCallState = "pending" - AsyncCallStateExecuting AsyncCallState = "executing" - AsyncCallStateSuccess AsyncCallState = "success" - AsyncCallStateError AsyncCallState = "error" -) - -func (e *AsyncCallState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = AsyncCallState(s) - case string: - *e = AsyncCallState(s) - default: - return fmt.Errorf("unsupported scan type for AsyncCallState: %T", src) - } - return nil -} - -type NullAsyncCallState struct { - AsyncCallState AsyncCallState - Valid bool // Valid is true if AsyncCallState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullAsyncCallState) Scan(value interface{}) error { - if value == nil { - ns.AsyncCallState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.AsyncCallState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullAsyncCallState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.AsyncCallState), nil -} - -type ControllerState string - -const ( - ControllerStateLive ControllerState = "live" - ControllerStateDead ControllerState = "dead" -) - -func (e *ControllerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = ControllerState(s) - case string: - *e = ControllerState(s) - default: - return fmt.Errorf("unsupported scan type for ControllerState: %T", src) - } - return nil -} - -type NullControllerState struct { - ControllerState ControllerState - Valid bool // Valid is true if ControllerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullControllerState) Scan(value interface{}) error { - if value == nil { - ns.ControllerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.ControllerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullControllerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.ControllerState), nil -} - -type EventType string - -const ( - EventTypeCall EventType = "call" - EventTypeLog EventType = "log" - EventTypeDeploymentCreated EventType = "deployment_created" - EventTypeDeploymentUpdated EventType = "deployment_updated" -) - -func (e *EventType) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = EventType(s) - case string: - *e = EventType(s) - default: - return fmt.Errorf("unsupported scan type for EventType: %T", src) - } - return nil -} - -type NullEventType struct { - EventType EventType - Valid bool // Valid is true if EventType is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullEventType) Scan(value interface{}) error { - if value == nil { - ns.EventType, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.EventType.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullEventType) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.EventType), nil -} - -type FsmStatus string - -const ( - FsmStatusRunning FsmStatus = "running" - FsmStatusCompleted FsmStatus = "completed" - FsmStatusFailed FsmStatus = "failed" -) - -func (e *FsmStatus) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = FsmStatus(s) - case string: - *e = FsmStatus(s) - default: - return fmt.Errorf("unsupported scan type for FsmStatus: %T", src) - } - return nil -} - -type NullFsmStatus struct { - FsmStatus FsmStatus - Valid bool // Valid is true if FsmStatus is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullFsmStatus) Scan(value interface{}) error { - if value == nil { - ns.FsmStatus, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.FsmStatus.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullFsmStatus) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.FsmStatus), nil -} - -type Origin string - -const ( - OriginIngress Origin = "ingress" - OriginCron Origin = "cron" - OriginPubsub Origin = "pubsub" -) - -func (e *Origin) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = Origin(s) - case string: - *e = Origin(s) - default: - return fmt.Errorf("unsupported scan type for Origin: %T", src) - } - return nil -} - -type NullOrigin struct { - Origin Origin - Valid bool // Valid is true if Origin is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullOrigin) Scan(value interface{}) error { - if value == nil { - ns.Origin, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.Origin.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullOrigin) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.Origin), nil -} - -type RunnerState string - -const ( - RunnerStateNew RunnerState = "new" - RunnerStateReserved RunnerState = "reserved" - RunnerStateAssigned RunnerState = "assigned" - RunnerStateDead RunnerState = "dead" -) - -func (e *RunnerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = RunnerState(s) - case string: - *e = RunnerState(s) - default: - return fmt.Errorf("unsupported scan type for RunnerState: %T", src) - } - return nil -} - -type NullRunnerState struct { - RunnerState RunnerState - Valid bool // Valid is true if RunnerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullRunnerState) Scan(value interface{}) error { - if value == nil { - ns.RunnerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.RunnerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullRunnerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.RunnerState), nil -} - -type TopicSubscriptionState string - -const ( - TopicSubscriptionStateIdle TopicSubscriptionState = "idle" - TopicSubscriptionStateExecuting TopicSubscriptionState = "executing" -) - -func (e *TopicSubscriptionState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = TopicSubscriptionState(s) - case string: - *e = TopicSubscriptionState(s) - default: - return fmt.Errorf("unsupported scan type for TopicSubscriptionState: %T", src) - } - return nil -} - -type NullTopicSubscriptionState struct { - TopicSubscriptionState TopicSubscriptionState - Valid bool // Valid is true if TopicSubscriptionState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullTopicSubscriptionState) Scan(value interface{}) error { - if value == nil { - ns.TopicSubscriptionState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.TopicSubscriptionState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullTopicSubscriptionState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.TopicSubscriptionState), nil -} - -type Artefact struct { - ID int64 - CreatedAt time.Time - Digest []byte - Content []byte -} - -type AsyncCall struct { - ID int64 - CreatedAt time.Time - LeaseID optional.Option[int64] - Verb schema.RefKey - State AsyncCallState - Origin string - ScheduledAt time.Time - Request encryption.EncryptedAsyncColumn - Response encryption.OptionalEncryptedAsyncColumn - Error optional.Option[string] - RemainingAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] - Catching bool - ParentRequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type Controller struct { - ID int64 - Key model.ControllerKey - Created time.Time - LastSeen time.Time - State ControllerState - Endpoint string -} - type CronJob struct { ID int64 Key model.CronJobKey @@ -380,158 +35,3 @@ type Deployment struct { Labels json.RawMessage MinReplicas int32 } - -type DeploymentArtefact struct { - ArtefactID int64 - DeploymentID int64 - CreatedAt time.Time - Executable bool - Path string -} - -type EncryptionKey struct { - ID int64 - Key []byte - CreatedAt time.Time - VerifyTimeline encryption.OptionalEncryptedTimelineColumn - VerifyAsync encryption.OptionalEncryptedAsyncColumn -} - -type FsmInstance struct { - ID int64 - CreatedAt time.Time - Fsm schema.RefKey - Key string - Status FsmStatus - CurrentState optional.Option[schema.RefKey] - DestinationState optional.Option[schema.RefKey] - AsyncCallID optional.Option[int64] - UpdatedAt time.Time -} - -type FsmNextEvent struct { - ID int64 - CreatedAt time.Time - FsmInstanceID int64 - NextState schema.RefKey - Request encryption.EncryptedAsyncColumn - RequestType sqltypes.Type -} - -type IngressRoute struct { - Method string - Path string - DeploymentID int64 - Module string - Verb string -} - -type Lease struct { - ID int64 - IdempotencyKey uuid.UUID - Key leases.Key - CreatedAt time.Time - ExpiresAt time.Time - Metadata pqtype.NullRawMessage -} - -type Module struct { - ID int64 - Language string - Name string -} - -type ModuleConfiguration struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Value json.RawMessage -} - -type ModuleSecret struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Url string -} - -type Request struct { - ID int64 - Origin Origin - Key model.RequestKey - SourceAddr string -} - -type Runner struct { - ID int64 - Key model.RunnerKey - Created time.Time - LastSeen time.Time - State RunnerState - Endpoint string - ModuleName optional.Option[string] - DeploymentID int64 - Labels json.RawMessage -} - -type Timeline struct { - ID int64 - TimeStamp time.Time - DeploymentID int64 - RequestID optional.Option[int64] - Type EventType - CustomKey1 optional.Option[string] - CustomKey2 optional.Option[string] - CustomKey3 optional.Option[string] - CustomKey4 optional.Option[string] - Payload encryption.EncryptedTimelineColumn - ParentRequestID optional.Option[string] -} - -type Topic struct { - ID int64 - Key model.TopicKey - CreatedAt time.Time - ModuleID int64 - Name string - Type string - Head optional.Option[int64] -} - -type TopicEvent struct { - ID int64 - CreatedAt time.Time - Key model.TopicEventKey - TopicID int64 - Payload encryption.EncryptedAsyncColumn - Caller optional.Option[string] - RequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type TopicSubscriber struct { - ID int64 - Key model.SubscriberKey - CreatedAt time.Time - TopicSubscriptionsID int64 - DeploymentID int64 - Sink schema.RefKey - RetryAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] -} - -type TopicSubscription struct { - ID int64 - Key model.SubscriptionKey - CreatedAt time.Time - TopicID int64 - ModuleID int64 - DeploymentID int64 - Name string - Cursor optional.Option[int64] - State TopicSubscriptionState -} diff --git a/backend/controller/dal/internal/sql/models.go b/backend/controller/dal/internal/sql/models.go index aca898349d..d5e201eb46 100644 --- a/backend/controller/dal/internal/sql/models.go +++ b/backend/controller/dal/internal/sql/models.go @@ -10,13 +10,11 @@ import ( "fmt" "time" - "github.com/TBD54566975/ftl/backend/controller/leases" "github.com/TBD54566975/ftl/backend/controller/sql/sqltypes" "github.com/TBD54566975/ftl/backend/schema" "github.com/TBD54566975/ftl/internal/encryption" "github.com/TBD54566975/ftl/internal/model" "github.com/alecthomas/types/optional" - "github.com/google/uuid" "github.com/sqlc-dev/pqtype" ) @@ -322,13 +320,6 @@ func (ns NullTopicSubscriptionState) Value() (driver.Value, error) { return string(ns.TopicSubscriptionState), nil } -type Artefact struct { - ID int64 - CreatedAt time.Time - Digest []byte - Content []byte -} - type AsyncCall struct { ID int64 CreatedAt time.Time @@ -381,22 +372,6 @@ type Deployment struct { MinReplicas int32 } -type DeploymentArtefact struct { - ArtefactID int64 - DeploymentID int64 - CreatedAt time.Time - Executable bool - Path string -} - -type EncryptionKey struct { - ID int64 - Key []byte - CreatedAt time.Time - VerifyTimeline encryption.OptionalEncryptedTimelineColumn - VerifyAsync encryption.OptionalEncryptedAsyncColumn -} - type FsmInstance struct { ID int64 CreatedAt time.Time @@ -418,64 +393,12 @@ type FsmNextEvent struct { RequestType sqltypes.Type } -type IngressRoute struct { - Method string - Path string - DeploymentID int64 - Module string - Verb string -} - -type Lease struct { - ID int64 - IdempotencyKey uuid.UUID - Key leases.Key - CreatedAt time.Time - ExpiresAt time.Time - Metadata pqtype.NullRawMessage -} - type Module struct { ID int64 Language string Name string } -type ModuleConfiguration struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Value json.RawMessage -} - -type ModuleSecret struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Url string -} - -type Request struct { - ID int64 - Origin Origin - Key model.RequestKey - SourceAddr string -} - -type Runner struct { - ID int64 - Key model.RunnerKey - Created time.Time - LastSeen time.Time - State RunnerState - Endpoint string - ModuleName optional.Option[string] - DeploymentID int64 - Labels json.RawMessage -} - type Timeline struct { ID int64 TimeStamp time.Time @@ -511,19 +434,6 @@ type TopicEvent struct { TraceContext pqtype.NullRawMessage } -type TopicSubscriber struct { - ID int64 - Key model.SubscriberKey - CreatedAt time.Time - TopicSubscriptionsID int64 - DeploymentID int64 - Sink schema.RefKey - RetryAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] -} - type TopicSubscription struct { ID int64 Key model.SubscriptionKey diff --git a/backend/controller/dal/internal/sql/querier.go b/backend/controller/dal/internal/sql/querier.go index 87f441bce2..382abea77d 100644 --- a/backend/controller/dal/internal/sql/querier.go +++ b/backend/controller/dal/internal/sql/querier.go @@ -34,6 +34,8 @@ type Querier interface { DeleteSubscribers(ctx context.Context, deployment model.DeploymentKey) ([]model.SubscriberKey, error) DeleteSubscriptions(ctx context.Context, deployment model.DeploymentKey) ([]model.SubscriptionKey, error) DeregisterRunner(ctx context.Context, key model.RunnerKey) (int64, error) + // This is a dummy query to ensure that the Timeline model is generated. + DummyQueryTimeline(ctx context.Context, id int64) (Timeline, error) FailAsyncCall(ctx context.Context, error string, iD int64) (bool, error) FailAsyncCallWithRetry(ctx context.Context, arg FailAsyncCallWithRetryParams) (bool, error) FailFSMInstance(ctx context.Context, fsm schema.RefKey, key string) (bool, error) diff --git a/backend/controller/dal/internal/sql/queries.sql b/backend/controller/dal/internal/sql/queries.sql index c57c62d92d..baacce5485 100644 --- a/backend/controller/dal/internal/sql/queries.sql +++ b/backend/controller/dal/internal/sql/queries.sql @@ -780,3 +780,7 @@ RETURNING parent_request_key, trace_context, catching; + +-- name: DummyQueryTimeline :one +-- This is a dummy query to ensure that the Timeline model is generated. +SELECT * FROM timeline WHERE id = @id; diff --git a/backend/controller/dal/internal/sql/queries.sql.go b/backend/controller/dal/internal/sql/queries.sql.go index 9843b87651..5992ca86c8 100644 --- a/backend/controller/dal/internal/sql/queries.sql.go +++ b/backend/controller/dal/internal/sql/queries.sql.go @@ -357,6 +357,30 @@ func (q *Queries) DeregisterRunner(ctx context.Context, key model.RunnerKey) (in return count, err } +const dummyQueryTimeline = `-- name: DummyQueryTimeline :one +SELECT id, time_stamp, deployment_id, request_id, type, custom_key_1, custom_key_2, custom_key_3, custom_key_4, payload, parent_request_id FROM timeline WHERE id = $1 +` + +// This is a dummy query to ensure that the Timeline model is generated. +func (q *Queries) DummyQueryTimeline(ctx context.Context, id int64) (Timeline, error) { + row := q.db.QueryRowContext(ctx, dummyQueryTimeline, id) + var i Timeline + err := row.Scan( + &i.ID, + &i.TimeStamp, + &i.DeploymentID, + &i.RequestID, + &i.Type, + &i.CustomKey1, + &i.CustomKey2, + &i.CustomKey3, + &i.CustomKey4, + &i.Payload, + &i.ParentRequestID, + ) + return i, err +} + const failAsyncCall = `-- name: FailAsyncCall :one UPDATE async_calls SET diff --git a/backend/controller/encryption/dal/internal/sql/models.go b/backend/controller/encryption/dal/internal/sql/models.go index aca898349d..76baffe98e 100644 --- a/backend/controller/encryption/dal/internal/sql/models.go +++ b/backend/controller/encryption/dal/internal/sql/models.go @@ -3,535 +3,3 @@ // sqlc v1.27.0 package sql - -import ( - "database/sql/driver" - "encoding/json" - "fmt" - "time" - - "github.com/TBD54566975/ftl/backend/controller/leases" - "github.com/TBD54566975/ftl/backend/controller/sql/sqltypes" - "github.com/TBD54566975/ftl/backend/schema" - "github.com/TBD54566975/ftl/internal/encryption" - "github.com/TBD54566975/ftl/internal/model" - "github.com/alecthomas/types/optional" - "github.com/google/uuid" - "github.com/sqlc-dev/pqtype" -) - -type AsyncCallState string - -const ( - AsyncCallStatePending AsyncCallState = "pending" - AsyncCallStateExecuting AsyncCallState = "executing" - AsyncCallStateSuccess AsyncCallState = "success" - AsyncCallStateError AsyncCallState = "error" -) - -func (e *AsyncCallState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = AsyncCallState(s) - case string: - *e = AsyncCallState(s) - default: - return fmt.Errorf("unsupported scan type for AsyncCallState: %T", src) - } - return nil -} - -type NullAsyncCallState struct { - AsyncCallState AsyncCallState - Valid bool // Valid is true if AsyncCallState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullAsyncCallState) Scan(value interface{}) error { - if value == nil { - ns.AsyncCallState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.AsyncCallState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullAsyncCallState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.AsyncCallState), nil -} - -type ControllerState string - -const ( - ControllerStateLive ControllerState = "live" - ControllerStateDead ControllerState = "dead" -) - -func (e *ControllerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = ControllerState(s) - case string: - *e = ControllerState(s) - default: - return fmt.Errorf("unsupported scan type for ControllerState: %T", src) - } - return nil -} - -type NullControllerState struct { - ControllerState ControllerState - Valid bool // Valid is true if ControllerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullControllerState) Scan(value interface{}) error { - if value == nil { - ns.ControllerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.ControllerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullControllerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.ControllerState), nil -} - -type EventType string - -const ( - EventTypeCall EventType = "call" - EventTypeLog EventType = "log" - EventTypeDeploymentCreated EventType = "deployment_created" - EventTypeDeploymentUpdated EventType = "deployment_updated" -) - -func (e *EventType) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = EventType(s) - case string: - *e = EventType(s) - default: - return fmt.Errorf("unsupported scan type for EventType: %T", src) - } - return nil -} - -type NullEventType struct { - EventType EventType - Valid bool // Valid is true if EventType is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullEventType) Scan(value interface{}) error { - if value == nil { - ns.EventType, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.EventType.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullEventType) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.EventType), nil -} - -type FsmStatus string - -const ( - FsmStatusRunning FsmStatus = "running" - FsmStatusCompleted FsmStatus = "completed" - FsmStatusFailed FsmStatus = "failed" -) - -func (e *FsmStatus) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = FsmStatus(s) - case string: - *e = FsmStatus(s) - default: - return fmt.Errorf("unsupported scan type for FsmStatus: %T", src) - } - return nil -} - -type NullFsmStatus struct { - FsmStatus FsmStatus - Valid bool // Valid is true if FsmStatus is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullFsmStatus) Scan(value interface{}) error { - if value == nil { - ns.FsmStatus, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.FsmStatus.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullFsmStatus) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.FsmStatus), nil -} - -type Origin string - -const ( - OriginIngress Origin = "ingress" - OriginCron Origin = "cron" - OriginPubsub Origin = "pubsub" -) - -func (e *Origin) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = Origin(s) - case string: - *e = Origin(s) - default: - return fmt.Errorf("unsupported scan type for Origin: %T", src) - } - return nil -} - -type NullOrigin struct { - Origin Origin - Valid bool // Valid is true if Origin is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullOrigin) Scan(value interface{}) error { - if value == nil { - ns.Origin, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.Origin.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullOrigin) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.Origin), nil -} - -type RunnerState string - -const ( - RunnerStateNew RunnerState = "new" - RunnerStateReserved RunnerState = "reserved" - RunnerStateAssigned RunnerState = "assigned" - RunnerStateDead RunnerState = "dead" -) - -func (e *RunnerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = RunnerState(s) - case string: - *e = RunnerState(s) - default: - return fmt.Errorf("unsupported scan type for RunnerState: %T", src) - } - return nil -} - -type NullRunnerState struct { - RunnerState RunnerState - Valid bool // Valid is true if RunnerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullRunnerState) Scan(value interface{}) error { - if value == nil { - ns.RunnerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.RunnerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullRunnerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.RunnerState), nil -} - -type TopicSubscriptionState string - -const ( - TopicSubscriptionStateIdle TopicSubscriptionState = "idle" - TopicSubscriptionStateExecuting TopicSubscriptionState = "executing" -) - -func (e *TopicSubscriptionState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = TopicSubscriptionState(s) - case string: - *e = TopicSubscriptionState(s) - default: - return fmt.Errorf("unsupported scan type for TopicSubscriptionState: %T", src) - } - return nil -} - -type NullTopicSubscriptionState struct { - TopicSubscriptionState TopicSubscriptionState - Valid bool // Valid is true if TopicSubscriptionState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullTopicSubscriptionState) Scan(value interface{}) error { - if value == nil { - ns.TopicSubscriptionState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.TopicSubscriptionState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullTopicSubscriptionState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.TopicSubscriptionState), nil -} - -type Artefact struct { - ID int64 - CreatedAt time.Time - Digest []byte - Content []byte -} - -type AsyncCall struct { - ID int64 - CreatedAt time.Time - LeaseID optional.Option[int64] - Verb schema.RefKey - State AsyncCallState - Origin string - ScheduledAt time.Time - Request encryption.EncryptedAsyncColumn - Response encryption.OptionalEncryptedAsyncColumn - Error optional.Option[string] - RemainingAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] - Catching bool - ParentRequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type Controller struct { - ID int64 - Key model.ControllerKey - Created time.Time - LastSeen time.Time - State ControllerState - Endpoint string -} - -type CronJob struct { - ID int64 - Key model.CronJobKey - DeploymentID int64 - Verb string - Schedule string - StartTime time.Time - NextExecution time.Time - ModuleName string - LastExecution optional.Option[time.Time] - LastAsyncCallID optional.Option[int64] -} - -type Deployment struct { - ID int64 - CreatedAt time.Time - ModuleID int64 - Key model.DeploymentKey - Schema *schema.Module - Labels json.RawMessage - MinReplicas int32 -} - -type DeploymentArtefact struct { - ArtefactID int64 - DeploymentID int64 - CreatedAt time.Time - Executable bool - Path string -} - -type EncryptionKey struct { - ID int64 - Key []byte - CreatedAt time.Time - VerifyTimeline encryption.OptionalEncryptedTimelineColumn - VerifyAsync encryption.OptionalEncryptedAsyncColumn -} - -type FsmInstance struct { - ID int64 - CreatedAt time.Time - Fsm schema.RefKey - Key string - Status FsmStatus - CurrentState optional.Option[schema.RefKey] - DestinationState optional.Option[schema.RefKey] - AsyncCallID optional.Option[int64] - UpdatedAt time.Time -} - -type FsmNextEvent struct { - ID int64 - CreatedAt time.Time - FsmInstanceID int64 - NextState schema.RefKey - Request encryption.EncryptedAsyncColumn - RequestType sqltypes.Type -} - -type IngressRoute struct { - Method string - Path string - DeploymentID int64 - Module string - Verb string -} - -type Lease struct { - ID int64 - IdempotencyKey uuid.UUID - Key leases.Key - CreatedAt time.Time - ExpiresAt time.Time - Metadata pqtype.NullRawMessage -} - -type Module struct { - ID int64 - Language string - Name string -} - -type ModuleConfiguration struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Value json.RawMessage -} - -type ModuleSecret struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Url string -} - -type Request struct { - ID int64 - Origin Origin - Key model.RequestKey - SourceAddr string -} - -type Runner struct { - ID int64 - Key model.RunnerKey - Created time.Time - LastSeen time.Time - State RunnerState - Endpoint string - ModuleName optional.Option[string] - DeploymentID int64 - Labels json.RawMessage -} - -type Timeline struct { - ID int64 - TimeStamp time.Time - DeploymentID int64 - RequestID optional.Option[int64] - Type EventType - CustomKey1 optional.Option[string] - CustomKey2 optional.Option[string] - CustomKey3 optional.Option[string] - CustomKey4 optional.Option[string] - Payload encryption.EncryptedTimelineColumn - ParentRequestID optional.Option[string] -} - -type Topic struct { - ID int64 - Key model.TopicKey - CreatedAt time.Time - ModuleID int64 - Name string - Type string - Head optional.Option[int64] -} - -type TopicEvent struct { - ID int64 - CreatedAt time.Time - Key model.TopicEventKey - TopicID int64 - Payload encryption.EncryptedAsyncColumn - Caller optional.Option[string] - RequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type TopicSubscriber struct { - ID int64 - Key model.SubscriberKey - CreatedAt time.Time - TopicSubscriptionsID int64 - DeploymentID int64 - Sink schema.RefKey - RetryAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] -} - -type TopicSubscription struct { - ID int64 - Key model.SubscriptionKey - CreatedAt time.Time - TopicID int64 - ModuleID int64 - DeploymentID int64 - Name string - Cursor optional.Option[int64] - State TopicSubscriptionState -} diff --git a/backend/controller/leases/dal/internal/sql/models.go b/backend/controller/leases/dal/internal/sql/models.go index aca898349d..76baffe98e 100644 --- a/backend/controller/leases/dal/internal/sql/models.go +++ b/backend/controller/leases/dal/internal/sql/models.go @@ -3,535 +3,3 @@ // sqlc v1.27.0 package sql - -import ( - "database/sql/driver" - "encoding/json" - "fmt" - "time" - - "github.com/TBD54566975/ftl/backend/controller/leases" - "github.com/TBD54566975/ftl/backend/controller/sql/sqltypes" - "github.com/TBD54566975/ftl/backend/schema" - "github.com/TBD54566975/ftl/internal/encryption" - "github.com/TBD54566975/ftl/internal/model" - "github.com/alecthomas/types/optional" - "github.com/google/uuid" - "github.com/sqlc-dev/pqtype" -) - -type AsyncCallState string - -const ( - AsyncCallStatePending AsyncCallState = "pending" - AsyncCallStateExecuting AsyncCallState = "executing" - AsyncCallStateSuccess AsyncCallState = "success" - AsyncCallStateError AsyncCallState = "error" -) - -func (e *AsyncCallState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = AsyncCallState(s) - case string: - *e = AsyncCallState(s) - default: - return fmt.Errorf("unsupported scan type for AsyncCallState: %T", src) - } - return nil -} - -type NullAsyncCallState struct { - AsyncCallState AsyncCallState - Valid bool // Valid is true if AsyncCallState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullAsyncCallState) Scan(value interface{}) error { - if value == nil { - ns.AsyncCallState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.AsyncCallState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullAsyncCallState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.AsyncCallState), nil -} - -type ControllerState string - -const ( - ControllerStateLive ControllerState = "live" - ControllerStateDead ControllerState = "dead" -) - -func (e *ControllerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = ControllerState(s) - case string: - *e = ControllerState(s) - default: - return fmt.Errorf("unsupported scan type for ControllerState: %T", src) - } - return nil -} - -type NullControllerState struct { - ControllerState ControllerState - Valid bool // Valid is true if ControllerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullControllerState) Scan(value interface{}) error { - if value == nil { - ns.ControllerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.ControllerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullControllerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.ControllerState), nil -} - -type EventType string - -const ( - EventTypeCall EventType = "call" - EventTypeLog EventType = "log" - EventTypeDeploymentCreated EventType = "deployment_created" - EventTypeDeploymentUpdated EventType = "deployment_updated" -) - -func (e *EventType) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = EventType(s) - case string: - *e = EventType(s) - default: - return fmt.Errorf("unsupported scan type for EventType: %T", src) - } - return nil -} - -type NullEventType struct { - EventType EventType - Valid bool // Valid is true if EventType is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullEventType) Scan(value interface{}) error { - if value == nil { - ns.EventType, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.EventType.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullEventType) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.EventType), nil -} - -type FsmStatus string - -const ( - FsmStatusRunning FsmStatus = "running" - FsmStatusCompleted FsmStatus = "completed" - FsmStatusFailed FsmStatus = "failed" -) - -func (e *FsmStatus) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = FsmStatus(s) - case string: - *e = FsmStatus(s) - default: - return fmt.Errorf("unsupported scan type for FsmStatus: %T", src) - } - return nil -} - -type NullFsmStatus struct { - FsmStatus FsmStatus - Valid bool // Valid is true if FsmStatus is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullFsmStatus) Scan(value interface{}) error { - if value == nil { - ns.FsmStatus, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.FsmStatus.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullFsmStatus) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.FsmStatus), nil -} - -type Origin string - -const ( - OriginIngress Origin = "ingress" - OriginCron Origin = "cron" - OriginPubsub Origin = "pubsub" -) - -func (e *Origin) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = Origin(s) - case string: - *e = Origin(s) - default: - return fmt.Errorf("unsupported scan type for Origin: %T", src) - } - return nil -} - -type NullOrigin struct { - Origin Origin - Valid bool // Valid is true if Origin is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullOrigin) Scan(value interface{}) error { - if value == nil { - ns.Origin, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.Origin.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullOrigin) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.Origin), nil -} - -type RunnerState string - -const ( - RunnerStateNew RunnerState = "new" - RunnerStateReserved RunnerState = "reserved" - RunnerStateAssigned RunnerState = "assigned" - RunnerStateDead RunnerState = "dead" -) - -func (e *RunnerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = RunnerState(s) - case string: - *e = RunnerState(s) - default: - return fmt.Errorf("unsupported scan type for RunnerState: %T", src) - } - return nil -} - -type NullRunnerState struct { - RunnerState RunnerState - Valid bool // Valid is true if RunnerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullRunnerState) Scan(value interface{}) error { - if value == nil { - ns.RunnerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.RunnerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullRunnerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.RunnerState), nil -} - -type TopicSubscriptionState string - -const ( - TopicSubscriptionStateIdle TopicSubscriptionState = "idle" - TopicSubscriptionStateExecuting TopicSubscriptionState = "executing" -) - -func (e *TopicSubscriptionState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = TopicSubscriptionState(s) - case string: - *e = TopicSubscriptionState(s) - default: - return fmt.Errorf("unsupported scan type for TopicSubscriptionState: %T", src) - } - return nil -} - -type NullTopicSubscriptionState struct { - TopicSubscriptionState TopicSubscriptionState - Valid bool // Valid is true if TopicSubscriptionState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullTopicSubscriptionState) Scan(value interface{}) error { - if value == nil { - ns.TopicSubscriptionState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.TopicSubscriptionState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullTopicSubscriptionState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.TopicSubscriptionState), nil -} - -type Artefact struct { - ID int64 - CreatedAt time.Time - Digest []byte - Content []byte -} - -type AsyncCall struct { - ID int64 - CreatedAt time.Time - LeaseID optional.Option[int64] - Verb schema.RefKey - State AsyncCallState - Origin string - ScheduledAt time.Time - Request encryption.EncryptedAsyncColumn - Response encryption.OptionalEncryptedAsyncColumn - Error optional.Option[string] - RemainingAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] - Catching bool - ParentRequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type Controller struct { - ID int64 - Key model.ControllerKey - Created time.Time - LastSeen time.Time - State ControllerState - Endpoint string -} - -type CronJob struct { - ID int64 - Key model.CronJobKey - DeploymentID int64 - Verb string - Schedule string - StartTime time.Time - NextExecution time.Time - ModuleName string - LastExecution optional.Option[time.Time] - LastAsyncCallID optional.Option[int64] -} - -type Deployment struct { - ID int64 - CreatedAt time.Time - ModuleID int64 - Key model.DeploymentKey - Schema *schema.Module - Labels json.RawMessage - MinReplicas int32 -} - -type DeploymentArtefact struct { - ArtefactID int64 - DeploymentID int64 - CreatedAt time.Time - Executable bool - Path string -} - -type EncryptionKey struct { - ID int64 - Key []byte - CreatedAt time.Time - VerifyTimeline encryption.OptionalEncryptedTimelineColumn - VerifyAsync encryption.OptionalEncryptedAsyncColumn -} - -type FsmInstance struct { - ID int64 - CreatedAt time.Time - Fsm schema.RefKey - Key string - Status FsmStatus - CurrentState optional.Option[schema.RefKey] - DestinationState optional.Option[schema.RefKey] - AsyncCallID optional.Option[int64] - UpdatedAt time.Time -} - -type FsmNextEvent struct { - ID int64 - CreatedAt time.Time - FsmInstanceID int64 - NextState schema.RefKey - Request encryption.EncryptedAsyncColumn - RequestType sqltypes.Type -} - -type IngressRoute struct { - Method string - Path string - DeploymentID int64 - Module string - Verb string -} - -type Lease struct { - ID int64 - IdempotencyKey uuid.UUID - Key leases.Key - CreatedAt time.Time - ExpiresAt time.Time - Metadata pqtype.NullRawMessage -} - -type Module struct { - ID int64 - Language string - Name string -} - -type ModuleConfiguration struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Value json.RawMessage -} - -type ModuleSecret struct { - ID int64 - CreatedAt time.Time - Module optional.Option[string] - Name string - Url string -} - -type Request struct { - ID int64 - Origin Origin - Key model.RequestKey - SourceAddr string -} - -type Runner struct { - ID int64 - Key model.RunnerKey - Created time.Time - LastSeen time.Time - State RunnerState - Endpoint string - ModuleName optional.Option[string] - DeploymentID int64 - Labels json.RawMessage -} - -type Timeline struct { - ID int64 - TimeStamp time.Time - DeploymentID int64 - RequestID optional.Option[int64] - Type EventType - CustomKey1 optional.Option[string] - CustomKey2 optional.Option[string] - CustomKey3 optional.Option[string] - CustomKey4 optional.Option[string] - Payload encryption.EncryptedTimelineColumn - ParentRequestID optional.Option[string] -} - -type Topic struct { - ID int64 - Key model.TopicKey - CreatedAt time.Time - ModuleID int64 - Name string - Type string - Head optional.Option[int64] -} - -type TopicEvent struct { - ID int64 - CreatedAt time.Time - Key model.TopicEventKey - TopicID int64 - Payload encryption.EncryptedAsyncColumn - Caller optional.Option[string] - RequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type TopicSubscriber struct { - ID int64 - Key model.SubscriberKey - CreatedAt time.Time - TopicSubscriptionsID int64 - DeploymentID int64 - Sink schema.RefKey - RetryAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] -} - -type TopicSubscription struct { - ID int64 - Key model.SubscriptionKey - CreatedAt time.Time - TopicID int64 - ModuleID int64 - DeploymentID int64 - Name string - Cursor optional.Option[int64] - State TopicSubscriptionState -} diff --git a/internal/configuration/dal/internal/sql/models.go b/internal/configuration/dal/internal/sql/models.go index aca898349d..847a0be927 100644 --- a/internal/configuration/dal/internal/sql/models.go +++ b/internal/configuration/dal/internal/sql/models.go @@ -5,442 +5,12 @@ package sql import ( - "database/sql/driver" "encoding/json" - "fmt" "time" - "github.com/TBD54566975/ftl/backend/controller/leases" - "github.com/TBD54566975/ftl/backend/controller/sql/sqltypes" - "github.com/TBD54566975/ftl/backend/schema" - "github.com/TBD54566975/ftl/internal/encryption" - "github.com/TBD54566975/ftl/internal/model" "github.com/alecthomas/types/optional" - "github.com/google/uuid" - "github.com/sqlc-dev/pqtype" ) -type AsyncCallState string - -const ( - AsyncCallStatePending AsyncCallState = "pending" - AsyncCallStateExecuting AsyncCallState = "executing" - AsyncCallStateSuccess AsyncCallState = "success" - AsyncCallStateError AsyncCallState = "error" -) - -func (e *AsyncCallState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = AsyncCallState(s) - case string: - *e = AsyncCallState(s) - default: - return fmt.Errorf("unsupported scan type for AsyncCallState: %T", src) - } - return nil -} - -type NullAsyncCallState struct { - AsyncCallState AsyncCallState - Valid bool // Valid is true if AsyncCallState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullAsyncCallState) Scan(value interface{}) error { - if value == nil { - ns.AsyncCallState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.AsyncCallState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullAsyncCallState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.AsyncCallState), nil -} - -type ControllerState string - -const ( - ControllerStateLive ControllerState = "live" - ControllerStateDead ControllerState = "dead" -) - -func (e *ControllerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = ControllerState(s) - case string: - *e = ControllerState(s) - default: - return fmt.Errorf("unsupported scan type for ControllerState: %T", src) - } - return nil -} - -type NullControllerState struct { - ControllerState ControllerState - Valid bool // Valid is true if ControllerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullControllerState) Scan(value interface{}) error { - if value == nil { - ns.ControllerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.ControllerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullControllerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.ControllerState), nil -} - -type EventType string - -const ( - EventTypeCall EventType = "call" - EventTypeLog EventType = "log" - EventTypeDeploymentCreated EventType = "deployment_created" - EventTypeDeploymentUpdated EventType = "deployment_updated" -) - -func (e *EventType) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = EventType(s) - case string: - *e = EventType(s) - default: - return fmt.Errorf("unsupported scan type for EventType: %T", src) - } - return nil -} - -type NullEventType struct { - EventType EventType - Valid bool // Valid is true if EventType is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullEventType) Scan(value interface{}) error { - if value == nil { - ns.EventType, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.EventType.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullEventType) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.EventType), nil -} - -type FsmStatus string - -const ( - FsmStatusRunning FsmStatus = "running" - FsmStatusCompleted FsmStatus = "completed" - FsmStatusFailed FsmStatus = "failed" -) - -func (e *FsmStatus) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = FsmStatus(s) - case string: - *e = FsmStatus(s) - default: - return fmt.Errorf("unsupported scan type for FsmStatus: %T", src) - } - return nil -} - -type NullFsmStatus struct { - FsmStatus FsmStatus - Valid bool // Valid is true if FsmStatus is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullFsmStatus) Scan(value interface{}) error { - if value == nil { - ns.FsmStatus, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.FsmStatus.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullFsmStatus) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.FsmStatus), nil -} - -type Origin string - -const ( - OriginIngress Origin = "ingress" - OriginCron Origin = "cron" - OriginPubsub Origin = "pubsub" -) - -func (e *Origin) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = Origin(s) - case string: - *e = Origin(s) - default: - return fmt.Errorf("unsupported scan type for Origin: %T", src) - } - return nil -} - -type NullOrigin struct { - Origin Origin - Valid bool // Valid is true if Origin is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullOrigin) Scan(value interface{}) error { - if value == nil { - ns.Origin, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.Origin.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullOrigin) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.Origin), nil -} - -type RunnerState string - -const ( - RunnerStateNew RunnerState = "new" - RunnerStateReserved RunnerState = "reserved" - RunnerStateAssigned RunnerState = "assigned" - RunnerStateDead RunnerState = "dead" -) - -func (e *RunnerState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = RunnerState(s) - case string: - *e = RunnerState(s) - default: - return fmt.Errorf("unsupported scan type for RunnerState: %T", src) - } - return nil -} - -type NullRunnerState struct { - RunnerState RunnerState - Valid bool // Valid is true if RunnerState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullRunnerState) Scan(value interface{}) error { - if value == nil { - ns.RunnerState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.RunnerState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullRunnerState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.RunnerState), nil -} - -type TopicSubscriptionState string - -const ( - TopicSubscriptionStateIdle TopicSubscriptionState = "idle" - TopicSubscriptionStateExecuting TopicSubscriptionState = "executing" -) - -func (e *TopicSubscriptionState) Scan(src interface{}) error { - switch s := src.(type) { - case []byte: - *e = TopicSubscriptionState(s) - case string: - *e = TopicSubscriptionState(s) - default: - return fmt.Errorf("unsupported scan type for TopicSubscriptionState: %T", src) - } - return nil -} - -type NullTopicSubscriptionState struct { - TopicSubscriptionState TopicSubscriptionState - Valid bool // Valid is true if TopicSubscriptionState is not NULL -} - -// Scan implements the Scanner interface. -func (ns *NullTopicSubscriptionState) Scan(value interface{}) error { - if value == nil { - ns.TopicSubscriptionState, ns.Valid = "", false - return nil - } - ns.Valid = true - return ns.TopicSubscriptionState.Scan(value) -} - -// Value implements the driver Valuer interface. -func (ns NullTopicSubscriptionState) Value() (driver.Value, error) { - if !ns.Valid { - return nil, nil - } - return string(ns.TopicSubscriptionState), nil -} - -type Artefact struct { - ID int64 - CreatedAt time.Time - Digest []byte - Content []byte -} - -type AsyncCall struct { - ID int64 - CreatedAt time.Time - LeaseID optional.Option[int64] - Verb schema.RefKey - State AsyncCallState - Origin string - ScheduledAt time.Time - Request encryption.EncryptedAsyncColumn - Response encryption.OptionalEncryptedAsyncColumn - Error optional.Option[string] - RemainingAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] - Catching bool - ParentRequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type Controller struct { - ID int64 - Key model.ControllerKey - Created time.Time - LastSeen time.Time - State ControllerState - Endpoint string -} - -type CronJob struct { - ID int64 - Key model.CronJobKey - DeploymentID int64 - Verb string - Schedule string - StartTime time.Time - NextExecution time.Time - ModuleName string - LastExecution optional.Option[time.Time] - LastAsyncCallID optional.Option[int64] -} - -type Deployment struct { - ID int64 - CreatedAt time.Time - ModuleID int64 - Key model.DeploymentKey - Schema *schema.Module - Labels json.RawMessage - MinReplicas int32 -} - -type DeploymentArtefact struct { - ArtefactID int64 - DeploymentID int64 - CreatedAt time.Time - Executable bool - Path string -} - -type EncryptionKey struct { - ID int64 - Key []byte - CreatedAt time.Time - VerifyTimeline encryption.OptionalEncryptedTimelineColumn - VerifyAsync encryption.OptionalEncryptedAsyncColumn -} - -type FsmInstance struct { - ID int64 - CreatedAt time.Time - Fsm schema.RefKey - Key string - Status FsmStatus - CurrentState optional.Option[schema.RefKey] - DestinationState optional.Option[schema.RefKey] - AsyncCallID optional.Option[int64] - UpdatedAt time.Time -} - -type FsmNextEvent struct { - ID int64 - CreatedAt time.Time - FsmInstanceID int64 - NextState schema.RefKey - Request encryption.EncryptedAsyncColumn - RequestType sqltypes.Type -} - -type IngressRoute struct { - Method string - Path string - DeploymentID int64 - Module string - Verb string -} - -type Lease struct { - ID int64 - IdempotencyKey uuid.UUID - Key leases.Key - CreatedAt time.Time - ExpiresAt time.Time - Metadata pqtype.NullRawMessage -} - -type Module struct { - ID int64 - Language string - Name string -} - type ModuleConfiguration struct { ID int64 CreatedAt time.Time @@ -456,82 +26,3 @@ type ModuleSecret struct { Name string Url string } - -type Request struct { - ID int64 - Origin Origin - Key model.RequestKey - SourceAddr string -} - -type Runner struct { - ID int64 - Key model.RunnerKey - Created time.Time - LastSeen time.Time - State RunnerState - Endpoint string - ModuleName optional.Option[string] - DeploymentID int64 - Labels json.RawMessage -} - -type Timeline struct { - ID int64 - TimeStamp time.Time - DeploymentID int64 - RequestID optional.Option[int64] - Type EventType - CustomKey1 optional.Option[string] - CustomKey2 optional.Option[string] - CustomKey3 optional.Option[string] - CustomKey4 optional.Option[string] - Payload encryption.EncryptedTimelineColumn - ParentRequestID optional.Option[string] -} - -type Topic struct { - ID int64 - Key model.TopicKey - CreatedAt time.Time - ModuleID int64 - Name string - Type string - Head optional.Option[int64] -} - -type TopicEvent struct { - ID int64 - CreatedAt time.Time - Key model.TopicEventKey - TopicID int64 - Payload encryption.EncryptedAsyncColumn - Caller optional.Option[string] - RequestKey optional.Option[string] - TraceContext pqtype.NullRawMessage -} - -type TopicSubscriber struct { - ID int64 - Key model.SubscriberKey - CreatedAt time.Time - TopicSubscriptionsID int64 - DeploymentID int64 - Sink schema.RefKey - RetryAttempts int32 - Backoff sqltypes.Duration - MaxBackoff sqltypes.Duration - CatchVerb optional.Option[schema.RefKey] -} - -type TopicSubscription struct { - ID int64 - Key model.SubscriptionKey - CreatedAt time.Time - TopicID int64 - ModuleID int64 - DeploymentID int64 - Name string - Cursor optional.Option[int64] - State TopicSubscriptionState -} diff --git a/sqlc.yaml b/sqlc.yaml index aee5d28260..1b1792132e 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -13,6 +13,7 @@ sql: gen: go: &gengo package: "sql" + omit_unused_structs: true out: "backend/controller/dal/internal/sql" emit_interface: true query_parameter_limit: 3