mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: Generalize log ownership to allow for scratch jobs (#182)
* refactor: Generalize log ownership to allow for scratch jobs Importing may fail when creating a project. We don't want to lose this output, but we don't want to allow users to create a failing project. This generalizes logs to soon enable one-off situations where a user can upload their archive, create a project, and watch the output parse to completion. * Improve file table schema by using hash * Fix racey test by allowing logs before * Add debug logging for PostgreSQL insert
This commit is contained in:
@@ -19,18 +19,18 @@ func New() database.Store {
|
||||
organizationMembers: make([]database.OrganizationMember, 0),
|
||||
users: make([]database.User, 0),
|
||||
|
||||
parameterValue: make([]database.ParameterValue, 0),
|
||||
project: make([]database.Project, 0),
|
||||
projectVersion: make([]database.ProjectVersion, 0),
|
||||
projectVersionLog: make([]database.ProjectVersionLog, 0),
|
||||
projectParameter: make([]database.ProjectParameter, 0),
|
||||
provisionerDaemons: make([]database.ProvisionerDaemon, 0),
|
||||
provisionerJobs: make([]database.ProvisionerJob, 0),
|
||||
workspace: make([]database.Workspace, 0),
|
||||
workspaceResource: make([]database.WorkspaceResource, 0),
|
||||
workspaceHistory: make([]database.WorkspaceHistory, 0),
|
||||
workspaceHistoryLog: make([]database.WorkspaceHistoryLog, 0),
|
||||
workspaceAgent: make([]database.WorkspaceAgent, 0),
|
||||
files: make([]database.File, 0),
|
||||
parameterValue: make([]database.ParameterValue, 0),
|
||||
project: make([]database.Project, 0),
|
||||
projectVersion: make([]database.ProjectVersion, 0),
|
||||
projectParameter: make([]database.ProjectParameter, 0),
|
||||
provisionerDaemons: make([]database.ProvisionerDaemon, 0),
|
||||
provisionerJobs: make([]database.ProvisionerJob, 0),
|
||||
provisionerJobLog: make([]database.ProvisionerJobLog, 0),
|
||||
workspace: make([]database.Workspace, 0),
|
||||
workspaceResource: make([]database.WorkspaceResource, 0),
|
||||
workspaceHistory: make([]database.WorkspaceHistory, 0),
|
||||
workspaceAgent: make([]database.WorkspaceAgent, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,23 +40,23 @@ type fakeQuerier struct {
|
||||
|
||||
// Legacy tables
|
||||
apiKeys []database.APIKey
|
||||
files []database.File
|
||||
organizations []database.Organization
|
||||
organizationMembers []database.OrganizationMember
|
||||
users []database.User
|
||||
|
||||
// New tables
|
||||
parameterValue []database.ParameterValue
|
||||
project []database.Project
|
||||
projectVersion []database.ProjectVersion
|
||||
projectVersionLog []database.ProjectVersionLog
|
||||
projectParameter []database.ProjectParameter
|
||||
provisionerDaemons []database.ProvisionerDaemon
|
||||
provisionerJobs []database.ProvisionerJob
|
||||
workspace []database.Workspace
|
||||
workspaceAgent []database.WorkspaceAgent
|
||||
workspaceHistory []database.WorkspaceHistory
|
||||
workspaceHistoryLog []database.WorkspaceHistoryLog
|
||||
workspaceResource []database.WorkspaceResource
|
||||
parameterValue []database.ParameterValue
|
||||
project []database.Project
|
||||
projectVersion []database.ProjectVersion
|
||||
projectParameter []database.ProjectParameter
|
||||
provisionerDaemons []database.ProvisionerDaemon
|
||||
provisionerJobs []database.ProvisionerJob
|
||||
provisionerJobLog []database.ProvisionerJobLog
|
||||
workspace []database.Workspace
|
||||
workspaceAgent []database.WorkspaceAgent
|
||||
workspaceHistory []database.WorkspaceHistory
|
||||
workspaceResource []database.WorkspaceResource
|
||||
}
|
||||
|
||||
// InTx doesn't rollback data properly for in-memory yet.
|
||||
@@ -104,6 +104,18 @@ func (q *fakeQuerier) GetAPIKeyByID(_ context.Context, id string) (database.APIK
|
||||
return database.APIKey{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetFileByHash(_ context.Context, hash string) (database.File, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for _, file := range q.files {
|
||||
if file.Hash == hash {
|
||||
return file, nil
|
||||
}
|
||||
}
|
||||
return database.File{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetUserByEmailOrUsername(_ context.Context, arg database.GetUserByEmailOrUsernameParams) (database.User, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
@@ -224,29 +236,6 @@ func (q *fakeQuerier) GetWorkspaceHistoryByWorkspaceIDWithoutAfter(_ context.Con
|
||||
return database.WorkspaceHistory{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetWorkspaceHistoryLogsByIDBetween(_ context.Context, arg database.GetWorkspaceHistoryLogsByIDBetweenParams) ([]database.WorkspaceHistoryLog, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
logs := make([]database.WorkspaceHistoryLog, 0)
|
||||
for _, workspaceHistoryLog := range q.workspaceHistoryLog {
|
||||
if workspaceHistoryLog.WorkspaceHistoryID.String() != arg.WorkspaceHistoryID.String() {
|
||||
continue
|
||||
}
|
||||
if workspaceHistoryLog.CreatedAt.After(arg.CreatedBefore) {
|
||||
continue
|
||||
}
|
||||
if workspaceHistoryLog.CreatedAt.Before(arg.CreatedAfter) {
|
||||
continue
|
||||
}
|
||||
logs = append(logs, workspaceHistoryLog)
|
||||
}
|
||||
if len(logs) == 0 {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetWorkspaceHistoryByWorkspaceID(_ context.Context, workspaceID uuid.UUID) ([]database.WorkspaceHistory, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
@@ -443,29 +432,6 @@ func (q *fakeQuerier) GetProjectVersionByProjectIDAndName(_ context.Context, arg
|
||||
return database.ProjectVersion{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetProjectVersionLogsByIDBetween(_ context.Context, arg database.GetProjectVersionLogsByIDBetweenParams) ([]database.ProjectVersionLog, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
logs := make([]database.ProjectVersionLog, 0)
|
||||
for _, projectVersionLog := range q.projectVersionLog {
|
||||
if projectVersionLog.ProjectVersionID.String() != arg.ProjectVersionID.String() {
|
||||
continue
|
||||
}
|
||||
if projectVersionLog.CreatedAt.After(arg.CreatedBefore) {
|
||||
continue
|
||||
}
|
||||
if projectVersionLog.CreatedAt.Before(arg.CreatedAfter) {
|
||||
continue
|
||||
}
|
||||
logs = append(logs, projectVersionLog)
|
||||
}
|
||||
if len(logs) == 0 {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetProjectVersionByID(_ context.Context, projectVersionID uuid.UUID) (database.ProjectVersion, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
@@ -567,6 +533,29 @@ func (q *fakeQuerier) GetProvisionerJobByID(_ context.Context, id uuid.UUID) (da
|
||||
return database.ProvisionerJob{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetProvisionerLogsByIDBetween(_ context.Context, arg database.GetProvisionerLogsByIDBetweenParams) ([]database.ProvisionerJobLog, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
logs := make([]database.ProvisionerJobLog, 0)
|
||||
for _, jobLog := range q.provisionerJobLog {
|
||||
if jobLog.JobID.String() != arg.JobID.String() {
|
||||
continue
|
||||
}
|
||||
if jobLog.CreatedAt.After(arg.CreatedBefore) {
|
||||
continue
|
||||
}
|
||||
if jobLog.CreatedAt.Before(arg.CreatedAfter) {
|
||||
continue
|
||||
}
|
||||
logs = append(logs, jobLog)
|
||||
}
|
||||
if len(logs) == 0 {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) InsertAPIKey(_ context.Context, arg database.InsertAPIKeyParams) (database.APIKey, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
@@ -593,6 +582,21 @@ func (q *fakeQuerier) InsertAPIKey(_ context.Context, arg database.InsertAPIKeyP
|
||||
return key, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) InsertFile(_ context.Context, arg database.InsertFileParams) (database.File, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
//nolint:gosimple
|
||||
file := database.File{
|
||||
Hash: arg.Hash,
|
||||
CreatedAt: arg.CreatedAt,
|
||||
Mimetype: arg.Mimetype,
|
||||
Data: arg.Data,
|
||||
}
|
||||
q.files = append(q.files, file)
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) InsertOrganization(_ context.Context, arg database.InsertOrganizationParams) (database.Organization, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
@@ -680,22 +684,22 @@ func (q *fakeQuerier) InsertProjectVersion(_ context.Context, arg database.Inser
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) InsertProjectVersionLogs(_ context.Context, arg database.InsertProjectVersionLogsParams) ([]database.ProjectVersionLog, error) {
|
||||
func (q *fakeQuerier) InsertProvisionerJobLogs(_ context.Context, arg database.InsertProvisionerJobLogsParams) ([]database.ProvisionerJobLog, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
logs := make([]database.ProjectVersionLog, 0)
|
||||
logs := make([]database.ProvisionerJobLog, 0)
|
||||
for index, output := range arg.Output {
|
||||
logs = append(logs, database.ProjectVersionLog{
|
||||
ProjectVersionID: arg.ProjectVersionID,
|
||||
ID: arg.ID[index],
|
||||
CreatedAt: arg.CreatedAt[index],
|
||||
Source: arg.Source[index],
|
||||
Level: arg.Level[index],
|
||||
Output: output,
|
||||
logs = append(logs, database.ProvisionerJobLog{
|
||||
JobID: arg.JobID,
|
||||
ID: arg.ID[index],
|
||||
CreatedAt: arg.CreatedAt[index],
|
||||
Source: arg.Source[index],
|
||||
Level: arg.Level[index],
|
||||
Output: output,
|
||||
})
|
||||
}
|
||||
q.projectVersionLog = append(q.projectVersionLog, logs...)
|
||||
q.provisionerJobLog = append(q.provisionerJobLog, logs...)
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
@@ -751,7 +755,6 @@ func (q *fakeQuerier) InsertProvisionerJob(_ context.Context, arg database.Inser
|
||||
UpdatedAt: arg.UpdatedAt,
|
||||
InitiatorID: arg.InitiatorID,
|
||||
Provisioner: arg.Provisioner,
|
||||
ProjectID: arg.ProjectID,
|
||||
Type: arg.Type,
|
||||
Input: arg.Input,
|
||||
}
|
||||
@@ -832,25 +835,6 @@ func (q *fakeQuerier) InsertWorkspaceHistory(_ context.Context, arg database.Ins
|
||||
return workspaceHistory, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) InsertWorkspaceHistoryLogs(_ context.Context, arg database.InsertWorkspaceHistoryLogsParams) ([]database.WorkspaceHistoryLog, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
logs := make([]database.WorkspaceHistoryLog, 0)
|
||||
for index, output := range arg.Output {
|
||||
logs = append(logs, database.WorkspaceHistoryLog{
|
||||
WorkspaceHistoryID: arg.WorkspaceHistoryID,
|
||||
ID: arg.ID[index],
|
||||
CreatedAt: arg.CreatedAt[index],
|
||||
Source: arg.Source[index],
|
||||
Level: arg.Level[index],
|
||||
Output: output,
|
||||
})
|
||||
}
|
||||
q.workspaceHistoryLog = append(q.workspaceHistoryLog, logs...)
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) InsertWorkspaceResource(_ context.Context, arg database.InsertWorkspaceResourceParams) (database.WorkspaceResource, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
Generated
+24
-33
@@ -87,6 +87,13 @@ CREATE TABLE api_keys (
|
||||
devurl_token boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE file (
|
||||
hash character varying(32) NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
mimetype character varying(64) NOT NULL,
|
||||
data bytea NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE licenses (
|
||||
id integer NOT NULL,
|
||||
license jsonb NOT NULL,
|
||||
@@ -169,15 +176,6 @@ CREATE TABLE project_version (
|
||||
import_job_id uuid NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE project_version_log (
|
||||
id uuid NOT NULL,
|
||||
project_version_id uuid NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
source log_source NOT NULL,
|
||||
level log_level NOT NULL,
|
||||
output character varying(1024) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE provisioner_daemon (
|
||||
id uuid NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
@@ -197,11 +195,19 @@ CREATE TABLE provisioner_job (
|
||||
initiator_id text NOT NULL,
|
||||
provisioner provisioner_type NOT NULL,
|
||||
type provisioner_job_type NOT NULL,
|
||||
project_id uuid NOT NULL,
|
||||
input jsonb NOT NULL,
|
||||
worker_id uuid
|
||||
);
|
||||
|
||||
CREATE TABLE provisioner_job_log (
|
||||
id uuid NOT NULL,
|
||||
job_id uuid NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
source log_source NOT NULL,
|
||||
level log_level NOT NULL,
|
||||
output character varying(1024) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE users (
|
||||
id text NOT NULL,
|
||||
email text NOT NULL,
|
||||
@@ -257,15 +263,6 @@ CREATE TABLE workspace_history (
|
||||
provision_job_id uuid NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE workspace_history_log (
|
||||
id uuid NOT NULL,
|
||||
workspace_history_id uuid NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
source log_source NOT NULL,
|
||||
level log_level NOT NULL,
|
||||
output character varying(1024) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE workspace_resource (
|
||||
id uuid NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
@@ -276,6 +273,9 @@ CREATE TABLE workspace_resource (
|
||||
workspace_agent_id uuid
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY file
|
||||
ADD CONSTRAINT file_hash_key UNIQUE (hash);
|
||||
|
||||
ALTER TABLE ONLY parameter_value
|
||||
ADD CONSTRAINT parameter_value_id_key UNIQUE (id);
|
||||
|
||||
@@ -297,9 +297,6 @@ ALTER TABLE ONLY project_parameter
|
||||
ALTER TABLE ONLY project_version
|
||||
ADD CONSTRAINT project_version_id_key UNIQUE (id);
|
||||
|
||||
ALTER TABLE ONLY project_version_log
|
||||
ADD CONSTRAINT project_version_log_id_key UNIQUE (id);
|
||||
|
||||
ALTER TABLE ONLY project_version
|
||||
ADD CONSTRAINT project_version_project_id_name_key UNIQUE (project_id, name);
|
||||
|
||||
@@ -312,15 +309,15 @@ ALTER TABLE ONLY provisioner_daemon
|
||||
ALTER TABLE ONLY provisioner_job
|
||||
ADD CONSTRAINT provisioner_job_id_key UNIQUE (id);
|
||||
|
||||
ALTER TABLE ONLY provisioner_job_log
|
||||
ADD CONSTRAINT provisioner_job_log_id_key UNIQUE (id);
|
||||
|
||||
ALTER TABLE ONLY workspace_agent
|
||||
ADD CONSTRAINT workspace_agent_id_key UNIQUE (id);
|
||||
|
||||
ALTER TABLE ONLY workspace_history
|
||||
ADD CONSTRAINT workspace_history_id_key UNIQUE (id);
|
||||
|
||||
ALTER TABLE ONLY workspace_history_log
|
||||
ADD CONSTRAINT workspace_history_log_id_key UNIQUE (id);
|
||||
|
||||
ALTER TABLE ONLY workspace_history
|
||||
ADD CONSTRAINT workspace_history_workspace_id_name_key UNIQUE (workspace_id, name);
|
||||
|
||||
@@ -342,21 +339,15 @@ ALTER TABLE ONLY workspace_resource
|
||||
ALTER TABLE ONLY project_parameter
|
||||
ADD CONSTRAINT project_parameter_project_version_id_fkey FOREIGN KEY (project_version_id) REFERENCES project_version(id) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE ONLY project_version_log
|
||||
ADD CONSTRAINT project_version_log_project_version_id_fkey FOREIGN KEY (project_version_id) REFERENCES project_version(id) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE ONLY project_version
|
||||
ADD CONSTRAINT project_version_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id);
|
||||
|
||||
ALTER TABLE ONLY provisioner_job
|
||||
ADD CONSTRAINT provisioner_job_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE;
|
||||
ALTER TABLE ONLY provisioner_job_log
|
||||
ADD CONSTRAINT provisioner_job_log_job_id_fkey FOREIGN KEY (job_id) REFERENCES provisioner_job(id) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE ONLY workspace_agent
|
||||
ADD CONSTRAINT workspace_agent_workspace_resource_id_fkey FOREIGN KEY (workspace_resource_id) REFERENCES workspace_resource(id) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE ONLY workspace_history_log
|
||||
ADD CONSTRAINT workspace_history_log_workspace_history_id_fkey FOREIGN KEY (workspace_history_id) REFERENCES workspace_history(id) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE ONLY workspace_history
|
||||
ADD CONSTRAINT workspace_history_project_version_id_fkey FOREIGN KEY (project_version_id) REFERENCES project_version(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
-- Store arbitrary data like project source code or avatars.
|
||||
CREATE TABLE file (
|
||||
hash varchar(32) NOT NULL UNIQUE,
|
||||
created_at timestamptz NOT NULL,
|
||||
mimetype varchar(64) NOT NULL,
|
||||
data bytea NOT NULL
|
||||
);
|
||||
|
||||
CREATE TYPE provisioner_type AS ENUM ('echo', 'terraform');
|
||||
|
||||
-- Project defines infrastructure that your software project
|
||||
@@ -90,25 +98,3 @@ CREATE TABLE project_parameter (
|
||||
validation_value_type varchar(64) NOT NULL,
|
||||
UNIQUE(project_version_id, name)
|
||||
);
|
||||
|
||||
CREATE TYPE log_level AS ENUM (
|
||||
'trace',
|
||||
'debug',
|
||||
'info',
|
||||
'warn',
|
||||
'error'
|
||||
);
|
||||
|
||||
CREATE TYPE log_source AS ENUM (
|
||||
'provisioner_daemon',
|
||||
'provisioner'
|
||||
);
|
||||
|
||||
CREATE TABLE project_version_log (
|
||||
id uuid NOT NULL UNIQUE,
|
||||
project_version_id uuid NOT NULL REFERENCES project_version (id) ON DELETE CASCADE,
|
||||
created_at timestamptz NOT NULL,
|
||||
source log_source NOT NULL,
|
||||
level log_level NOT NULL,
|
||||
output varchar(1024) NOT NULL
|
||||
);
|
||||
@@ -64,12 +64,3 @@ CREATE TABLE workspace_agent (
|
||||
-- Identifies resources.
|
||||
resource_metadata jsonb NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE workspace_history_log (
|
||||
id uuid NOT NULL UNIQUE,
|
||||
workspace_history_id uuid NOT NULL REFERENCES workspace_history (id) ON DELETE CASCADE,
|
||||
created_at timestamptz NOT NULL,
|
||||
source log_source NOT NULL,
|
||||
level log_level NOT NULL,
|
||||
output varchar(1024) NOT NULL
|
||||
);
|
||||
@@ -24,11 +24,32 @@ CREATE TABLE IF NOT EXISTS provisioner_job (
|
||||
initiator_id text NOT NULL,
|
||||
provisioner provisioner_type NOT NULL,
|
||||
type provisioner_job_type NOT NULL,
|
||||
project_id uuid NOT NULL REFERENCES project(id) ON DELETE CASCADE,
|
||||
input jsonb NOT NULL,
|
||||
worker_id uuid
|
||||
);
|
||||
|
||||
CREATE TYPE log_level AS ENUM (
|
||||
'trace',
|
||||
'debug',
|
||||
'info',
|
||||
'warn',
|
||||
'error'
|
||||
);
|
||||
|
||||
CREATE TYPE log_source AS ENUM (
|
||||
'provisioner_daemon',
|
||||
'provisioner'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS provisioner_job_log (
|
||||
id uuid NOT NULL UNIQUE,
|
||||
job_id uuid NOT NULL REFERENCES provisioner_job (id) ON DELETE CASCADE,
|
||||
created_at timestamptz NOT NULL,
|
||||
source log_source NOT NULL,
|
||||
level log_level NOT NULL,
|
||||
output varchar(1024) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TYPE parameter_scope AS ENUM (
|
||||
'organization',
|
||||
'project',
|
||||
|
||||
+16
-19
@@ -266,6 +266,13 @@ type APIKey struct {
|
||||
DevurlToken bool `db:"devurl_token" json:"devurl_token"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Hash string `db:"hash" json:"hash"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Mimetype string `db:"mimetype" json:"mimetype"`
|
||||
Data []byte `db:"data" json:"data"`
|
||||
}
|
||||
|
||||
type License struct {
|
||||
ID int32 `db:"id" json:"id"`
|
||||
License json.RawMessage `db:"license" json:"license"`
|
||||
@@ -348,15 +355,6 @@ type ProjectVersion struct {
|
||||
ImportJobID uuid.UUID `db:"import_job_id" json:"import_job_id"`
|
||||
}
|
||||
|
||||
type ProjectVersionLog struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
ProjectVersionID uuid.UUID `db:"project_version_id" json:"project_version_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Source LogSource `db:"source" json:"source"`
|
||||
Level LogLevel `db:"level" json:"level"`
|
||||
Output string `db:"output" json:"output"`
|
||||
}
|
||||
|
||||
type ProvisionerDaemon struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
@@ -376,11 +374,19 @@ type ProvisionerJob struct {
|
||||
InitiatorID string `db:"initiator_id" json:"initiator_id"`
|
||||
Provisioner ProvisionerType `db:"provisioner" json:"provisioner"`
|
||||
Type ProvisionerJobType `db:"type" json:"type"`
|
||||
ProjectID uuid.UUID `db:"project_id" json:"project_id"`
|
||||
Input json.RawMessage `db:"input" json:"input"`
|
||||
WorkerID uuid.NullUUID `db:"worker_id" json:"worker_id"`
|
||||
}
|
||||
|
||||
type ProvisionerJobLog struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
JobID uuid.UUID `db:"job_id" json:"job_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Source LogSource `db:"source" json:"source"`
|
||||
Level LogLevel `db:"level" json:"level"`
|
||||
Output string `db:"output" json:"output"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID string `db:"id" json:"id"`
|
||||
Email string `db:"email" json:"email"`
|
||||
@@ -436,15 +442,6 @@ type WorkspaceHistory struct {
|
||||
ProvisionJobID uuid.UUID `db:"provision_job_id" json:"provision_job_id"`
|
||||
}
|
||||
|
||||
type WorkspaceHistoryLog struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
WorkspaceHistoryID uuid.UUID `db:"workspace_history_id" json:"workspace_history_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Source LogSource `db:"source" json:"source"`
|
||||
Level LogLevel `db:"level" json:"level"`
|
||||
Output string `db:"output" json:"output"`
|
||||
}
|
||||
|
||||
type WorkspaceResource struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
|
||||
+4
-4
@@ -11,6 +11,7 @@ import (
|
||||
type querier interface {
|
||||
AcquireProvisionerJob(ctx context.Context, arg AcquireProvisionerJobParams) (ProvisionerJob, error)
|
||||
GetAPIKeyByID(ctx context.Context, id string) (APIKey, error)
|
||||
GetFileByHash(ctx context.Context, hash string) (File, error)
|
||||
GetOrganizationByID(ctx context.Context, id string) (Organization, error)
|
||||
GetOrganizationByName(ctx context.Context, name string) (Organization, error)
|
||||
GetOrganizationMemberByUserID(ctx context.Context, arg GetOrganizationMemberByUserIDParams) (OrganizationMember, error)
|
||||
@@ -22,11 +23,11 @@ type querier interface {
|
||||
GetProjectVersionByID(ctx context.Context, id uuid.UUID) (ProjectVersion, error)
|
||||
GetProjectVersionByProjectID(ctx context.Context, projectID uuid.UUID) ([]ProjectVersion, error)
|
||||
GetProjectVersionByProjectIDAndName(ctx context.Context, arg GetProjectVersionByProjectIDAndNameParams) (ProjectVersion, error)
|
||||
GetProjectVersionLogsByIDBetween(ctx context.Context, arg GetProjectVersionLogsByIDBetweenParams) ([]ProjectVersionLog, error)
|
||||
GetProjectsByOrganizationIDs(ctx context.Context, ids []string) ([]Project, error)
|
||||
GetProvisionerDaemonByID(ctx context.Context, id uuid.UUID) (ProvisionerDaemon, error)
|
||||
GetProvisionerDaemons(ctx context.Context) ([]ProvisionerDaemon, error)
|
||||
GetProvisionerJobByID(ctx context.Context, id uuid.UUID) (ProvisionerJob, error)
|
||||
GetProvisionerLogsByIDBetween(ctx context.Context, arg GetProvisionerLogsByIDBetweenParams) ([]ProvisionerJobLog, error)
|
||||
GetUserByEmailOrUsername(ctx context.Context, arg GetUserByEmailOrUsernameParams) (User, error)
|
||||
GetUserByID(ctx context.Context, id string) (User, error)
|
||||
GetUserCount(ctx context.Context) (int64, error)
|
||||
@@ -37,25 +38,24 @@ type querier interface {
|
||||
GetWorkspaceHistoryByWorkspaceID(ctx context.Context, workspaceID uuid.UUID) ([]WorkspaceHistory, error)
|
||||
GetWorkspaceHistoryByWorkspaceIDAndName(ctx context.Context, arg GetWorkspaceHistoryByWorkspaceIDAndNameParams) (WorkspaceHistory, error)
|
||||
GetWorkspaceHistoryByWorkspaceIDWithoutAfter(ctx context.Context, workspaceID uuid.UUID) (WorkspaceHistory, error)
|
||||
GetWorkspaceHistoryLogsByIDBetween(ctx context.Context, arg GetWorkspaceHistoryLogsByIDBetweenParams) ([]WorkspaceHistoryLog, error)
|
||||
GetWorkspaceResourcesByHistoryID(ctx context.Context, workspaceHistoryID uuid.UUID) ([]WorkspaceResource, error)
|
||||
GetWorkspacesByProjectAndUserID(ctx context.Context, arg GetWorkspacesByProjectAndUserIDParams) ([]Workspace, error)
|
||||
GetWorkspacesByUserID(ctx context.Context, ownerID string) ([]Workspace, error)
|
||||
InsertAPIKey(ctx context.Context, arg InsertAPIKeyParams) (APIKey, error)
|
||||
InsertFile(ctx context.Context, arg InsertFileParams) (File, error)
|
||||
InsertOrganization(ctx context.Context, arg InsertOrganizationParams) (Organization, error)
|
||||
InsertOrganizationMember(ctx context.Context, arg InsertOrganizationMemberParams) (OrganizationMember, error)
|
||||
InsertParameterValue(ctx context.Context, arg InsertParameterValueParams) (ParameterValue, error)
|
||||
InsertProject(ctx context.Context, arg InsertProjectParams) (Project, error)
|
||||
InsertProjectParameter(ctx context.Context, arg InsertProjectParameterParams) (ProjectParameter, error)
|
||||
InsertProjectVersion(ctx context.Context, arg InsertProjectVersionParams) (ProjectVersion, error)
|
||||
InsertProjectVersionLogs(ctx context.Context, arg InsertProjectVersionLogsParams) ([]ProjectVersionLog, error)
|
||||
InsertProvisionerDaemon(ctx context.Context, arg InsertProvisionerDaemonParams) (ProvisionerDaemon, error)
|
||||
InsertProvisionerJob(ctx context.Context, arg InsertProvisionerJobParams) (ProvisionerJob, error)
|
||||
InsertProvisionerJobLogs(ctx context.Context, arg InsertProvisionerJobLogsParams) ([]ProvisionerJobLog, error)
|
||||
InsertUser(ctx context.Context, arg InsertUserParams) (User, error)
|
||||
InsertWorkspace(ctx context.Context, arg InsertWorkspaceParams) (Workspace, error)
|
||||
InsertWorkspaceAgent(ctx context.Context, arg InsertWorkspaceAgentParams) (WorkspaceAgent, error)
|
||||
InsertWorkspaceHistory(ctx context.Context, arg InsertWorkspaceHistoryParams) (WorkspaceHistory, error)
|
||||
InsertWorkspaceHistoryLogs(ctx context.Context, arg InsertWorkspaceHistoryLogsParams) ([]WorkspaceHistoryLog, error)
|
||||
InsertWorkspaceResource(ctx context.Context, arg InsertWorkspaceResourceParams) (WorkspaceResource, error)
|
||||
UpdateAPIKeyByID(ctx context.Context, arg UpdateAPIKeyByIDParams) error
|
||||
UpdateProvisionerDaemonByID(ctx context.Context, arg UpdateProvisionerDaemonByIDParams) error
|
||||
|
||||
+31
-41
@@ -46,6 +46,16 @@ WHERE
|
||||
LIMIT
|
||||
1;
|
||||
|
||||
-- name: GetFileByHash :one
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
file
|
||||
WHERE
|
||||
hash = $1
|
||||
LIMIT
|
||||
1;
|
||||
|
||||
-- name: GetUserByID :one
|
||||
SELECT
|
||||
*
|
||||
@@ -188,13 +198,13 @@ FROM
|
||||
WHERE
|
||||
id = $1;
|
||||
|
||||
-- name: GetProjectVersionLogsByIDBetween :many
|
||||
-- name: GetProvisionerLogsByIDBetween :many
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
project_version_log
|
||||
provisioner_job_log
|
||||
WHERE
|
||||
project_version_id = @project_version_id
|
||||
job_id = @job_id
|
||||
AND (
|
||||
created_at >= @created_after
|
||||
OR created_at <= @created_before
|
||||
@@ -298,20 +308,6 @@ WHERE
|
||||
LIMIT
|
||||
1;
|
||||
|
||||
-- name: GetWorkspaceHistoryLogsByIDBetween :many
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
workspace_history_log
|
||||
WHERE
|
||||
workspace_history_id = @workspace_history_id
|
||||
AND (
|
||||
created_at >= @created_after
|
||||
OR created_at <= @created_before
|
||||
)
|
||||
ORDER BY
|
||||
created_at;
|
||||
|
||||
-- name: GetWorkspaceResourcesByHistoryID :many
|
||||
SELECT
|
||||
*
|
||||
@@ -366,6 +362,23 @@ VALUES
|
||||
$15
|
||||
) RETURNING *;
|
||||
|
||||
-- name: InsertFile :one
|
||||
INSERT INTO
|
||||
file (hash, created_at, mimetype, data)
|
||||
VALUES
|
||||
($1, $2, $3, $4) RETURNING *;
|
||||
|
||||
-- name: InsertProvisionerJobLogs :many
|
||||
INSERT INTO
|
||||
provisioner_job_log
|
||||
SELECT
|
||||
unnest(@id :: uuid [ ]) AS id,
|
||||
@job_id :: uuid AS job_id,
|
||||
unnest(@created_at :: timestamptz [ ]) AS created_at,
|
||||
unnest(@source :: log_source [ ]) as source,
|
||||
unnest(@level :: log_level [ ]) as level,
|
||||
unnest(@output :: varchar(1024) [ ]) as output RETURNING *;
|
||||
|
||||
-- name: InsertOrganization :one
|
||||
INSERT INTO
|
||||
organizations (id, name, description, created_at, updated_at)
|
||||
@@ -430,17 +443,6 @@ INSERT INTO
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
|
||||
|
||||
-- name: InsertProjectVersionLogs :many
|
||||
INSERT INTO
|
||||
project_version_log
|
||||
SELECT
|
||||
@project_version_id :: uuid AS project_version_id,
|
||||
unnest(@id :: uuid [ ]) AS id,
|
||||
unnest(@created_at :: timestamptz [ ]) AS created_at,
|
||||
unnest(@source :: log_source [ ]) as source,
|
||||
unnest(@level :: log_level [ ]) as level,
|
||||
unnest(@output :: varchar(1024) [ ]) as output RETURNING *;
|
||||
|
||||
-- name: InsertProjectParameter :one
|
||||
INSERT INTO
|
||||
project_parameter (
|
||||
@@ -498,11 +500,10 @@ INSERT INTO
|
||||
initiator_id,
|
||||
provisioner,
|
||||
type,
|
||||
project_id,
|
||||
input
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *;
|
||||
($1, $2, $3, $4, $5, $6, $7) RETURNING *;
|
||||
|
||||
-- name: InsertUser :one
|
||||
INSERT INTO
|
||||
@@ -564,17 +565,6 @@ INSERT INTO
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *;
|
||||
|
||||
-- name: InsertWorkspaceHistoryLogs :many
|
||||
INSERT INTO
|
||||
workspace_history_log
|
||||
SELECT
|
||||
unnest(@id :: uuid [ ]) AS id,
|
||||
@workspace_history_id :: uuid AS workspace_history_id,
|
||||
unnest(@created_at :: timestamptz [ ]) AS created_at,
|
||||
unnest(@source :: log_source [ ]) as source,
|
||||
unnest(@level :: log_level [ ]) as level,
|
||||
unnest(@output :: varchar(1024) [ ]) as output RETURNING *;
|
||||
|
||||
-- name: InsertWorkspaceResource :one
|
||||
INSERT INTO
|
||||
workspace_resource (
|
||||
|
||||
+166
-227
@@ -37,7 +37,7 @@ WHERE
|
||||
SKIP LOCKED
|
||||
LIMIT
|
||||
1
|
||||
) RETURNING id, created_at, updated_at, started_at, cancelled_at, completed_at, error, initiator_id, provisioner, type, project_id, input, worker_id
|
||||
) RETURNING id, created_at, updated_at, started_at, cancelled_at, completed_at, error, initiator_id, provisioner, type, input, worker_id
|
||||
`
|
||||
|
||||
type AcquireProvisionerJobParams struct {
|
||||
@@ -66,7 +66,6 @@ func (q *sqlQuerier) AcquireProvisionerJob(ctx context.Context, arg AcquireProvi
|
||||
&i.InitiatorID,
|
||||
&i.Provisioner,
|
||||
&i.Type,
|
||||
&i.ProjectID,
|
||||
&i.Input,
|
||||
&i.WorkerID,
|
||||
)
|
||||
@@ -107,6 +106,29 @@ func (q *sqlQuerier) GetAPIKeyByID(ctx context.Context, id string) (APIKey, erro
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getFileByHash = `-- name: GetFileByHash :one
|
||||
SELECT
|
||||
hash, created_at, mimetype, data
|
||||
FROM
|
||||
file
|
||||
WHERE
|
||||
hash = $1
|
||||
LIMIT
|
||||
1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetFileByHash(ctx context.Context, hash string) (File, error) {
|
||||
row := q.db.QueryRowContext(ctx, getFileByHash, hash)
|
||||
var i File
|
||||
err := row.Scan(
|
||||
&i.Hash,
|
||||
&i.CreatedAt,
|
||||
&i.Mimetype,
|
||||
&i.Data,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getOrganizationByID = `-- name: GetOrganizationByID :one
|
||||
SELECT
|
||||
id, name, description, created_at, updated_at, "default", auto_off_threshold, cpu_provisioning_rate, memory_provisioning_rate, workspace_auto_off
|
||||
@@ -500,57 +522,6 @@ func (q *sqlQuerier) GetProjectVersionByProjectIDAndName(ctx context.Context, ar
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getProjectVersionLogsByIDBetween = `-- name: GetProjectVersionLogsByIDBetween :many
|
||||
SELECT
|
||||
id, project_version_id, created_at, source, level, output
|
||||
FROM
|
||||
project_version_log
|
||||
WHERE
|
||||
project_version_id = $1
|
||||
AND (
|
||||
created_at >= $2
|
||||
OR created_at <= $3
|
||||
)
|
||||
ORDER BY
|
||||
created_at
|
||||
`
|
||||
|
||||
type GetProjectVersionLogsByIDBetweenParams struct {
|
||||
ProjectVersionID uuid.UUID `db:"project_version_id" json:"project_version_id"`
|
||||
CreatedAfter time.Time `db:"created_after" json:"created_after"`
|
||||
CreatedBefore time.Time `db:"created_before" json:"created_before"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetProjectVersionLogsByIDBetween(ctx context.Context, arg GetProjectVersionLogsByIDBetweenParams) ([]ProjectVersionLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getProjectVersionLogsByIDBetween, arg.ProjectVersionID, arg.CreatedAfter, arg.CreatedBefore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ProjectVersionLog
|
||||
for rows.Next() {
|
||||
var i ProjectVersionLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectVersionID,
|
||||
&i.CreatedAt,
|
||||
&i.Source,
|
||||
&i.Level,
|
||||
&i.Output,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getProjectsByOrganizationIDs = `-- name: GetProjectsByOrganizationIDs :many
|
||||
SELECT
|
||||
id, created_at, updated_at, organization_id, name, provisioner, active_version_id
|
||||
@@ -651,7 +622,7 @@ func (q *sqlQuerier) GetProvisionerDaemons(ctx context.Context) ([]ProvisionerDa
|
||||
|
||||
const getProvisionerJobByID = `-- name: GetProvisionerJobByID :one
|
||||
SELECT
|
||||
id, created_at, updated_at, started_at, cancelled_at, completed_at, error, initiator_id, provisioner, type, project_id, input, worker_id
|
||||
id, created_at, updated_at, started_at, cancelled_at, completed_at, error, initiator_id, provisioner, type, input, worker_id
|
||||
FROM
|
||||
provisioner_job
|
||||
WHERE
|
||||
@@ -672,13 +643,63 @@ func (q *sqlQuerier) GetProvisionerJobByID(ctx context.Context, id uuid.UUID) (P
|
||||
&i.InitiatorID,
|
||||
&i.Provisioner,
|
||||
&i.Type,
|
||||
&i.ProjectID,
|
||||
&i.Input,
|
||||
&i.WorkerID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getProvisionerLogsByIDBetween = `-- name: GetProvisionerLogsByIDBetween :many
|
||||
SELECT
|
||||
id, job_id, created_at, source, level, output
|
||||
FROM
|
||||
provisioner_job_log
|
||||
WHERE
|
||||
job_id = $1
|
||||
AND (
|
||||
created_at >= $2
|
||||
OR created_at <= $3
|
||||
)
|
||||
ORDER BY
|
||||
created_at
|
||||
`
|
||||
|
||||
type GetProvisionerLogsByIDBetweenParams struct {
|
||||
JobID uuid.UUID `db:"job_id" json:"job_id"`
|
||||
CreatedAfter time.Time `db:"created_after" json:"created_after"`
|
||||
CreatedBefore time.Time `db:"created_before" json:"created_before"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetProvisionerLogsByIDBetween(ctx context.Context, arg GetProvisionerLogsByIDBetweenParams) ([]ProvisionerJobLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getProvisionerLogsByIDBetween, arg.JobID, arg.CreatedAfter, arg.CreatedBefore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ProvisionerJobLog
|
||||
for rows.Next() {
|
||||
var i ProvisionerJobLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.JobID,
|
||||
&i.CreatedAt,
|
||||
&i.Source,
|
||||
&i.Level,
|
||||
&i.Output,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getUserByEmailOrUsername = `-- name: GetUserByEmailOrUsername :one
|
||||
SELECT
|
||||
id, email, name, revoked, login_type, hashed_password, created_at, updated_at, temporary_password, avatar_hash, ssh_key_regenerated_at, username, dotfiles_git_uri, roles, status, relatime, gpg_key_regenerated_at, _decomissioned, shell
|
||||
@@ -1011,57 +1032,6 @@ func (q *sqlQuerier) GetWorkspaceHistoryByWorkspaceIDWithoutAfter(ctx context.Co
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getWorkspaceHistoryLogsByIDBetween = `-- name: GetWorkspaceHistoryLogsByIDBetween :many
|
||||
SELECT
|
||||
id, workspace_history_id, created_at, source, level, output
|
||||
FROM
|
||||
workspace_history_log
|
||||
WHERE
|
||||
workspace_history_id = $1
|
||||
AND (
|
||||
created_at >= $2
|
||||
OR created_at <= $3
|
||||
)
|
||||
ORDER BY
|
||||
created_at
|
||||
`
|
||||
|
||||
type GetWorkspaceHistoryLogsByIDBetweenParams struct {
|
||||
WorkspaceHistoryID uuid.UUID `db:"workspace_history_id" json:"workspace_history_id"`
|
||||
CreatedAfter time.Time `db:"created_after" json:"created_after"`
|
||||
CreatedBefore time.Time `db:"created_before" json:"created_before"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetWorkspaceHistoryLogsByIDBetween(ctx context.Context, arg GetWorkspaceHistoryLogsByIDBetweenParams) ([]WorkspaceHistoryLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getWorkspaceHistoryLogsByIDBetween, arg.WorkspaceHistoryID, arg.CreatedAfter, arg.CreatedBefore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []WorkspaceHistoryLog
|
||||
for rows.Next() {
|
||||
var i WorkspaceHistoryLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceHistoryID,
|
||||
&i.CreatedAt,
|
||||
&i.Source,
|
||||
&i.Level,
|
||||
&i.Output,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getWorkspaceResourcesByHistoryID = `-- name: GetWorkspaceResourcesByHistoryID :many
|
||||
SELECT
|
||||
id, created_at, workspace_history_id, type, name, workspace_agent_token, workspace_agent_id
|
||||
@@ -1282,6 +1252,37 @@ func (q *sqlQuerier) InsertAPIKey(ctx context.Context, arg InsertAPIKeyParams) (
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertFile = `-- name: InsertFile :one
|
||||
INSERT INTO
|
||||
file (hash, created_at, mimetype, data)
|
||||
VALUES
|
||||
($1, $2, $3, $4) RETURNING hash, created_at, mimetype, data
|
||||
`
|
||||
|
||||
type InsertFileParams struct {
|
||||
Hash string `db:"hash" json:"hash"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Mimetype string `db:"mimetype" json:"mimetype"`
|
||||
Data []byte `db:"data" json:"data"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertFile(ctx context.Context, arg InsertFileParams) (File, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertFile,
|
||||
arg.Hash,
|
||||
arg.CreatedAt,
|
||||
arg.Mimetype,
|
||||
arg.Data,
|
||||
)
|
||||
var i File
|
||||
err := row.Scan(
|
||||
&i.Hash,
|
||||
&i.CreatedAt,
|
||||
&i.Mimetype,
|
||||
&i.Data,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertOrganization = `-- name: InsertOrganization :one
|
||||
INSERT INTO
|
||||
organizations (id, name, description, created_at, updated_at)
|
||||
@@ -1628,64 +1629,6 @@ func (q *sqlQuerier) InsertProjectVersion(ctx context.Context, arg InsertProject
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertProjectVersionLogs = `-- name: InsertProjectVersionLogs :many
|
||||
INSERT INTO
|
||||
project_version_log
|
||||
SELECT
|
||||
$1 :: uuid AS project_version_id,
|
||||
unnest($2 :: uuid [ ]) AS id,
|
||||
unnest($3 :: timestamptz [ ]) AS created_at,
|
||||
unnest($4 :: log_source [ ]) as source,
|
||||
unnest($5 :: log_level [ ]) as level,
|
||||
unnest($6 :: varchar(1024) [ ]) as output RETURNING id, project_version_id, created_at, source, level, output
|
||||
`
|
||||
|
||||
type InsertProjectVersionLogsParams struct {
|
||||
ProjectVersionID uuid.UUID `db:"project_version_id" json:"project_version_id"`
|
||||
ID []uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt []time.Time `db:"created_at" json:"created_at"`
|
||||
Source []LogSource `db:"source" json:"source"`
|
||||
Level []LogLevel `db:"level" json:"level"`
|
||||
Output []string `db:"output" json:"output"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertProjectVersionLogs(ctx context.Context, arg InsertProjectVersionLogsParams) ([]ProjectVersionLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, insertProjectVersionLogs,
|
||||
arg.ProjectVersionID,
|
||||
pq.Array(arg.ID),
|
||||
pq.Array(arg.CreatedAt),
|
||||
pq.Array(arg.Source),
|
||||
pq.Array(arg.Level),
|
||||
pq.Array(arg.Output),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ProjectVersionLog
|
||||
for rows.Next() {
|
||||
var i ProjectVersionLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectVersionID,
|
||||
&i.CreatedAt,
|
||||
&i.Source,
|
||||
&i.Level,
|
||||
&i.Output,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const insertProvisionerDaemon = `-- name: InsertProvisionerDaemon :one
|
||||
INSERT INTO
|
||||
provisioner_daemon (id, created_at, name, provisioners)
|
||||
@@ -1727,11 +1670,10 @@ INSERT INTO
|
||||
initiator_id,
|
||||
provisioner,
|
||||
type,
|
||||
project_id,
|
||||
input
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, created_at, updated_at, started_at, cancelled_at, completed_at, error, initiator_id, provisioner, type, project_id, input, worker_id
|
||||
($1, $2, $3, $4, $5, $6, $7) RETURNING id, created_at, updated_at, started_at, cancelled_at, completed_at, error, initiator_id, provisioner, type, input, worker_id
|
||||
`
|
||||
|
||||
type InsertProvisionerJobParams struct {
|
||||
@@ -1741,7 +1683,6 @@ type InsertProvisionerJobParams struct {
|
||||
InitiatorID string `db:"initiator_id" json:"initiator_id"`
|
||||
Provisioner ProvisionerType `db:"provisioner" json:"provisioner"`
|
||||
Type ProvisionerJobType `db:"type" json:"type"`
|
||||
ProjectID uuid.UUID `db:"project_id" json:"project_id"`
|
||||
Input json.RawMessage `db:"input" json:"input"`
|
||||
}
|
||||
|
||||
@@ -1753,7 +1694,6 @@ func (q *sqlQuerier) InsertProvisionerJob(ctx context.Context, arg InsertProvisi
|
||||
arg.InitiatorID,
|
||||
arg.Provisioner,
|
||||
arg.Type,
|
||||
arg.ProjectID,
|
||||
arg.Input,
|
||||
)
|
||||
var i ProvisionerJob
|
||||
@@ -1768,13 +1708,70 @@ func (q *sqlQuerier) InsertProvisionerJob(ctx context.Context, arg InsertProvisi
|
||||
&i.InitiatorID,
|
||||
&i.Provisioner,
|
||||
&i.Type,
|
||||
&i.ProjectID,
|
||||
&i.Input,
|
||||
&i.WorkerID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertProvisionerJobLogs = `-- name: InsertProvisionerJobLogs :many
|
||||
INSERT INTO
|
||||
provisioner_job_log
|
||||
SELECT
|
||||
unnest($1 :: uuid [ ]) AS id,
|
||||
$2 :: uuid AS job_id,
|
||||
unnest($3 :: timestamptz [ ]) AS created_at,
|
||||
unnest($4 :: log_source [ ]) as source,
|
||||
unnest($5 :: log_level [ ]) as level,
|
||||
unnest($6 :: varchar(1024) [ ]) as output RETURNING id, job_id, created_at, source, level, output
|
||||
`
|
||||
|
||||
type InsertProvisionerJobLogsParams struct {
|
||||
ID []uuid.UUID `db:"id" json:"id"`
|
||||
JobID uuid.UUID `db:"job_id" json:"job_id"`
|
||||
CreatedAt []time.Time `db:"created_at" json:"created_at"`
|
||||
Source []LogSource `db:"source" json:"source"`
|
||||
Level []LogLevel `db:"level" json:"level"`
|
||||
Output []string `db:"output" json:"output"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertProvisionerJobLogs(ctx context.Context, arg InsertProvisionerJobLogsParams) ([]ProvisionerJobLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, insertProvisionerJobLogs,
|
||||
pq.Array(arg.ID),
|
||||
arg.JobID,
|
||||
pq.Array(arg.CreatedAt),
|
||||
pq.Array(arg.Source),
|
||||
pq.Array(arg.Level),
|
||||
pq.Array(arg.Output),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ProvisionerJobLog
|
||||
for rows.Next() {
|
||||
var i ProvisionerJobLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.JobID,
|
||||
&i.CreatedAt,
|
||||
&i.Source,
|
||||
&i.Level,
|
||||
&i.Output,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const insertUser = `-- name: InsertUser :one
|
||||
INSERT INTO
|
||||
users (
|
||||
@@ -1992,64 +1989,6 @@ func (q *sqlQuerier) InsertWorkspaceHistory(ctx context.Context, arg InsertWorks
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertWorkspaceHistoryLogs = `-- name: InsertWorkspaceHistoryLogs :many
|
||||
INSERT INTO
|
||||
workspace_history_log
|
||||
SELECT
|
||||
unnest($1 :: uuid [ ]) AS id,
|
||||
$2 :: uuid AS workspace_history_id,
|
||||
unnest($3 :: timestamptz [ ]) AS created_at,
|
||||
unnest($4 :: log_source [ ]) as source,
|
||||
unnest($5 :: log_level [ ]) as level,
|
||||
unnest($6 :: varchar(1024) [ ]) as output RETURNING id, workspace_history_id, created_at, source, level, output
|
||||
`
|
||||
|
||||
type InsertWorkspaceHistoryLogsParams struct {
|
||||
ID []uuid.UUID `db:"id" json:"id"`
|
||||
WorkspaceHistoryID uuid.UUID `db:"workspace_history_id" json:"workspace_history_id"`
|
||||
CreatedAt []time.Time `db:"created_at" json:"created_at"`
|
||||
Source []LogSource `db:"source" json:"source"`
|
||||
Level []LogLevel `db:"level" json:"level"`
|
||||
Output []string `db:"output" json:"output"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertWorkspaceHistoryLogs(ctx context.Context, arg InsertWorkspaceHistoryLogsParams) ([]WorkspaceHistoryLog, error) {
|
||||
rows, err := q.db.QueryContext(ctx, insertWorkspaceHistoryLogs,
|
||||
pq.Array(arg.ID),
|
||||
arg.WorkspaceHistoryID,
|
||||
pq.Array(arg.CreatedAt),
|
||||
pq.Array(arg.Source),
|
||||
pq.Array(arg.Level),
|
||||
pq.Array(arg.Output),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []WorkspaceHistoryLog
|
||||
for rows.Next() {
|
||||
var i WorkspaceHistoryLog
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceHistoryID,
|
||||
&i.CreatedAt,
|
||||
&i.Source,
|
||||
&i.Level,
|
||||
&i.Output,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const insertWorkspaceResource = `-- name: InsertWorkspaceResource :one
|
||||
INSERT INTO
|
||||
workspace_resource (
|
||||
|
||||
Reference in New Issue
Block a user