mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: add derpserver to wsproxy, add proxies to derpmap (#7311)
This commit is contained in:
@ -1123,6 +1123,13 @@ func (q *querier) GetQuotaConsumedForUser(ctx context.Context, userID uuid.UUID)
|
||||
return q.db.GetQuotaConsumedForUser(ctx, userID)
|
||||
}
|
||||
|
||||
func (q *querier) GetReplicaByID(ctx context.Context, id uuid.UUID) (database.Replica, error) {
|
||||
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
|
||||
return database.Replica{}, err
|
||||
}
|
||||
return q.db.GetReplicaByID(ctx, id)
|
||||
}
|
||||
|
||||
func (q *querier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Time) ([]database.Replica, error) {
|
||||
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
|
||||
return nil, err
|
||||
|
@ -1820,6 +1820,19 @@ func (q *FakeQuerier) GetQuotaConsumedForUser(_ context.Context, userID uuid.UUI
|
||||
return sum, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetReplicaByID(_ context.Context, id uuid.UUID) (database.Replica, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
for _, replica := range q.replicas {
|
||||
if replica.ID == id {
|
||||
return replica, nil
|
||||
}
|
||||
}
|
||||
|
||||
return database.Replica{}, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetReplicasUpdatedAfter(_ context.Context, updatedAt time.Time) ([]database.Replica, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
@ -3684,6 +3697,7 @@ func (q *FakeQuerier) InsertReplica(_ context.Context, arg database.InsertReplic
|
||||
RelayAddress: arg.RelayAddress,
|
||||
Version: arg.Version,
|
||||
DatabaseLatency: arg.DatabaseLatency,
|
||||
Primary: arg.Primary,
|
||||
}
|
||||
q.replicas = append(q.replicas, replica)
|
||||
return replica, nil
|
||||
@ -4125,10 +4139,14 @@ func (q *FakeQuerier) InsertWorkspaceProxy(_ context.Context, arg database.Inser
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
lastRegionID := int32(0)
|
||||
for _, p := range q.workspaceProxies {
|
||||
if !p.Deleted && p.Name == arg.Name {
|
||||
return database.WorkspaceProxy{}, errDuplicateKey
|
||||
}
|
||||
if p.RegionID > lastRegionID {
|
||||
lastRegionID = p.RegionID
|
||||
}
|
||||
}
|
||||
|
||||
p := database.WorkspaceProxy{
|
||||
@ -4136,7 +4154,9 @@ func (q *FakeQuerier) InsertWorkspaceProxy(_ context.Context, arg database.Inser
|
||||
Name: arg.Name,
|
||||
DisplayName: arg.DisplayName,
|
||||
Icon: arg.Icon,
|
||||
DerpEnabled: arg.DerpEnabled,
|
||||
TokenHashedSecret: arg.TokenHashedSecret,
|
||||
RegionID: lastRegionID + 1,
|
||||
CreatedAt: arg.CreatedAt,
|
||||
UpdatedAt: arg.UpdatedAt,
|
||||
Deleted: false,
|
||||
@ -4208,6 +4228,7 @@ func (q *FakeQuerier) RegisterWorkspaceProxy(_ context.Context, arg database.Reg
|
||||
if p.ID == arg.ID {
|
||||
p.Url = arg.Url
|
||||
p.WildcardHostname = arg.WildcardHostname
|
||||
p.DerpEnabled = arg.DerpEnabled
|
||||
p.UpdatedAt = database.Now()
|
||||
q.workspaceProxies[i] = p
|
||||
return p, nil
|
||||
@ -4419,6 +4440,7 @@ func (q *FakeQuerier) UpdateReplica(_ context.Context, arg database.UpdateReplic
|
||||
replica.Version = arg.Version
|
||||
replica.Error = arg.Error
|
||||
replica.DatabaseLatency = arg.DatabaseLatency
|
||||
replica.Primary = arg.Primary
|
||||
q.replicas[index] = replica
|
||||
return replica, nil
|
||||
}
|
||||
|
@ -545,6 +545,13 @@ func (m metricsStore) GetQuotaConsumedForUser(ctx context.Context, ownerID uuid.
|
||||
return consumed, err
|
||||
}
|
||||
|
||||
func (m metricsStore) GetReplicaByID(ctx context.Context, id uuid.UUID) (database.Replica, error) {
|
||||
start := time.Now()
|
||||
replica, err := m.s.GetReplicaByID(ctx, id)
|
||||
m.queryLatencies.WithLabelValues("GetReplicaByID").Observe(time.Since(start).Seconds())
|
||||
return replica, err
|
||||
}
|
||||
|
||||
func (m metricsStore) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Time) ([]database.Replica, error) {
|
||||
start := time.Now()
|
||||
replicas, err := m.s.GetReplicasUpdatedAfter(ctx, updatedAt)
|
||||
|
@ -1076,6 +1076,21 @@ func (mr *MockStoreMockRecorder) GetQuotaConsumedForUser(arg0, arg1 interface{})
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQuotaConsumedForUser", reflect.TypeOf((*MockStore)(nil).GetQuotaConsumedForUser), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetReplicaByID mocks base method.
|
||||
func (m *MockStore) GetReplicaByID(arg0 context.Context, arg1 uuid.UUID) (database.Replica, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetReplicaByID", arg0, arg1)
|
||||
ret0, _ := ret[0].(database.Replica)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetReplicaByID indicates an expected call of GetReplicaByID.
|
||||
func (mr *MockStoreMockRecorder) GetReplicaByID(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReplicaByID", reflect.TypeOf((*MockStore)(nil).GetReplicaByID), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetReplicasUpdatedAfter mocks base method.
|
||||
func (m *MockStore) GetReplicasUpdatedAfter(arg0 context.Context, arg1 time.Time) ([]database.Replica, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
22
coderd/database/dump.sql
generated
22
coderd/database/dump.sql
generated
@ -418,7 +418,8 @@ CREATE TABLE replicas (
|
||||
relay_address text NOT NULL,
|
||||
database_latency integer NOT NULL,
|
||||
version text NOT NULL,
|
||||
error text DEFAULT ''::text NOT NULL
|
||||
error text DEFAULT ''::text NOT NULL,
|
||||
"primary" boolean DEFAULT true NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE site_configs (
|
||||
@ -862,7 +863,9 @@ CREATE TABLE workspace_proxies (
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
updated_at timestamp with time zone NOT NULL,
|
||||
deleted boolean NOT NULL,
|
||||
token_hashed_secret bytea NOT NULL
|
||||
token_hashed_secret bytea NOT NULL,
|
||||
region_id integer NOT NULL,
|
||||
derp_enabled boolean DEFAULT true NOT NULL
|
||||
);
|
||||
|
||||
COMMENT ON COLUMN workspace_proxies.icon IS 'Expects an emoji character. (/emojis/1f1fa-1f1f8.png)';
|
||||
@ -875,6 +878,16 @@ COMMENT ON COLUMN workspace_proxies.deleted IS 'Boolean indicator of a deleted w
|
||||
|
||||
COMMENT ON COLUMN workspace_proxies.token_hashed_secret IS 'Hashed secret is used to authenticate the workspace proxy using a session token.';
|
||||
|
||||
CREATE SEQUENCE workspace_proxies_region_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE workspace_proxies_region_id_seq OWNED BY workspace_proxies.region_id;
|
||||
|
||||
CREATE TABLE workspace_resource_metadata (
|
||||
workspace_resource_id uuid NOT NULL,
|
||||
key character varying(1024) NOT NULL,
|
||||
@ -927,6 +940,8 @@ ALTER TABLE ONLY provisioner_job_logs ALTER COLUMN id SET DEFAULT nextval('provi
|
||||
|
||||
ALTER TABLE ONLY workspace_agent_startup_logs ALTER COLUMN id SET DEFAULT nextval('workspace_agent_startup_logs_id_seq'::regclass);
|
||||
|
||||
ALTER TABLE ONLY workspace_proxies ALTER COLUMN region_id SET DEFAULT nextval('workspace_proxies_region_id_seq'::regclass);
|
||||
|
||||
ALTER TABLE ONLY workspace_resource_metadata ALTER COLUMN id SET DEFAULT nextval('workspace_resource_metadata_id_seq'::regclass);
|
||||
|
||||
ALTER TABLE ONLY workspace_agent_stats
|
||||
@ -1058,6 +1073,9 @@ ALTER TABLE ONLY workspace_builds
|
||||
ALTER TABLE ONLY workspace_proxies
|
||||
ADD CONSTRAINT workspace_proxies_pkey PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE ONLY workspace_proxies
|
||||
ADD CONSTRAINT workspace_proxies_region_id_unique UNIQUE (region_id);
|
||||
|
||||
ALTER TABLE ONLY workspace_resource_metadata
|
||||
ADD CONSTRAINT workspace_resource_metadata_name UNIQUE (workspace_resource_id, key);
|
||||
|
||||
|
15
coderd/database/migrations/000142_proxy_derp.down.sql
Normal file
15
coderd/database/migrations/000142_proxy_derp.down.sql
Normal file
@ -0,0 +1,15 @@
|
||||
BEGIN;
|
||||
|
||||
-- drop any rows that aren't primary replicas
|
||||
DELETE FROM replicas
|
||||
WHERE "primary" = false;
|
||||
|
||||
ALTER TABLE replicas
|
||||
DROP COLUMN "primary";
|
||||
|
||||
ALTER TABLE workspace_proxies
|
||||
DROP CONSTRAINT workspace_proxies_region_id_unique,
|
||||
DROP COLUMN region_id,
|
||||
DROP COLUMN derp_enabled;
|
||||
|
||||
COMMIT;
|
13
coderd/database/migrations/000142_proxy_derp.up.sql
Normal file
13
coderd/database/migrations/000142_proxy_derp.up.sql
Normal file
@ -0,0 +1,13 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE replicas
|
||||
ADD COLUMN "primary" boolean NOT NULL DEFAULT true;
|
||||
|
||||
ALTER TABLE workspace_proxies
|
||||
-- Adding a serial to a table without a default value will be filled as you
|
||||
-- would expect on versions of Postgres >= 9 AFAIK (which we require).
|
||||
ADD COLUMN region_id serial NOT NULL,
|
||||
ADD COLUMN derp_enabled boolean NOT NULL DEFAULT true,
|
||||
ADD CONSTRAINT workspace_proxies_region_id_unique UNIQUE (region_id);
|
||||
|
||||
COMMIT;
|
@ -1539,6 +1539,7 @@ type Replica struct {
|
||||
DatabaseLatency int32 `db:"database_latency" json:"database_latency"`
|
||||
Version string `db:"version" json:"version"`
|
||||
Error string `db:"error" json:"error"`
|
||||
Primary bool `db:"primary" json:"primary"`
|
||||
}
|
||||
|
||||
type SiteConfig struct {
|
||||
@ -1936,6 +1937,8 @@ type WorkspaceProxy struct {
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
// Hashed secret is used to authenticate the workspace proxy using a session token.
|
||||
TokenHashedSecret []byte `db:"token_hashed_secret" json:"token_hashed_secret"`
|
||||
RegionID int32 `db:"region_id" json:"region_id"`
|
||||
DerpEnabled bool `db:"derp_enabled" json:"derp_enabled"`
|
||||
}
|
||||
|
||||
type WorkspaceResource struct {
|
||||
|
@ -97,6 +97,7 @@ type sqlcQuerier interface {
|
||||
GetProvisionerLogsAfterID(ctx context.Context, arg GetProvisionerLogsAfterIDParams) ([]ProvisionerJobLog, error)
|
||||
GetQuotaAllowanceForUser(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||
GetQuotaConsumedForUser(ctx context.Context, ownerID uuid.UUID) (int64, error)
|
||||
GetReplicaByID(ctx context.Context, id uuid.UUID) (Replica, error)
|
||||
GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Time) ([]Replica, error)
|
||||
GetServiceBanner(ctx context.Context) (string, error)
|
||||
GetTailnetAgents(ctx context.Context, id uuid.UUID) ([]TailnetAgent, error)
|
||||
|
@ -2848,7 +2848,7 @@ func (q *sqlQuerier) UpdateProvisionerJobWithCompleteByID(ctx context.Context, a
|
||||
|
||||
const getWorkspaceProxies = `-- name: GetWorkspaceProxies :many
|
||||
SELECT
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret, region_id, derp_enabled
|
||||
FROM
|
||||
workspace_proxies
|
||||
WHERE
|
||||
@ -2875,6 +2875,8 @@ func (q *sqlQuerier) GetWorkspaceProxies(ctx context.Context) ([]WorkspaceProxy,
|
||||
&i.UpdatedAt,
|
||||
&i.Deleted,
|
||||
&i.TokenHashedSecret,
|
||||
&i.RegionID,
|
||||
&i.DerpEnabled,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2891,7 +2893,7 @@ func (q *sqlQuerier) GetWorkspaceProxies(ctx context.Context) ([]WorkspaceProxy,
|
||||
|
||||
const getWorkspaceProxyByHostname = `-- name: GetWorkspaceProxyByHostname :one
|
||||
SELECT
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret, region_id, derp_enabled
|
||||
FROM
|
||||
workspace_proxies
|
||||
WHERE
|
||||
@ -2947,13 +2949,15 @@ func (q *sqlQuerier) GetWorkspaceProxyByHostname(ctx context.Context, arg GetWor
|
||||
&i.UpdatedAt,
|
||||
&i.Deleted,
|
||||
&i.TokenHashedSecret,
|
||||
&i.RegionID,
|
||||
&i.DerpEnabled,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getWorkspaceProxyByID = `-- name: GetWorkspaceProxyByID :one
|
||||
SELECT
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret, region_id, derp_enabled
|
||||
FROM
|
||||
workspace_proxies
|
||||
WHERE
|
||||
@ -2976,13 +2980,15 @@ func (q *sqlQuerier) GetWorkspaceProxyByID(ctx context.Context, id uuid.UUID) (W
|
||||
&i.UpdatedAt,
|
||||
&i.Deleted,
|
||||
&i.TokenHashedSecret,
|
||||
&i.RegionID,
|
||||
&i.DerpEnabled,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getWorkspaceProxyByName = `-- name: GetWorkspaceProxyByName :one
|
||||
SELECT
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret
|
||||
id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret, region_id, derp_enabled
|
||||
FROM
|
||||
workspace_proxies
|
||||
WHERE
|
||||
@ -3006,6 +3012,8 @@ func (q *sqlQuerier) GetWorkspaceProxyByName(ctx context.Context, name string) (
|
||||
&i.UpdatedAt,
|
||||
&i.Deleted,
|
||||
&i.TokenHashedSecret,
|
||||
&i.RegionID,
|
||||
&i.DerpEnabled,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -3019,13 +3027,14 @@ INSERT INTO
|
||||
name,
|
||||
display_name,
|
||||
icon,
|
||||
derp_enabled,
|
||||
token_hashed_secret,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted
|
||||
)
|
||||
VALUES
|
||||
($1, '', '', $2, $3, $4, $5, $6, $7, false) RETURNING id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret
|
||||
($1, '', '', $2, $3, $4, $5, $6, $7, $8, false) RETURNING id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret, region_id, derp_enabled
|
||||
`
|
||||
|
||||
type InsertWorkspaceProxyParams struct {
|
||||
@ -3033,6 +3042,7 @@ type InsertWorkspaceProxyParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
DerpEnabled bool `db:"derp_enabled" json:"derp_enabled"`
|
||||
TokenHashedSecret []byte `db:"token_hashed_secret" json:"token_hashed_secret"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
@ -3044,6 +3054,7 @@ func (q *sqlQuerier) InsertWorkspaceProxy(ctx context.Context, arg InsertWorkspa
|
||||
arg.Name,
|
||||
arg.DisplayName,
|
||||
arg.Icon,
|
||||
arg.DerpEnabled,
|
||||
arg.TokenHashedSecret,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
@ -3060,6 +3071,8 @@ func (q *sqlQuerier) InsertWorkspaceProxy(ctx context.Context, arg InsertWorkspa
|
||||
&i.UpdatedAt,
|
||||
&i.Deleted,
|
||||
&i.TokenHashedSecret,
|
||||
&i.RegionID,
|
||||
&i.DerpEnabled,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -3068,22 +3081,29 @@ const registerWorkspaceProxy = `-- name: RegisterWorkspaceProxy :one
|
||||
UPDATE
|
||||
workspace_proxies
|
||||
SET
|
||||
url = $1,
|
||||
wildcard_hostname = $2,
|
||||
url = $1 :: text,
|
||||
wildcard_hostname = $2 :: text,
|
||||
derp_enabled = $3 :: boolean,
|
||||
updated_at = Now()
|
||||
WHERE
|
||||
id = $3
|
||||
RETURNING id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret
|
||||
id = $4
|
||||
RETURNING id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret, region_id, derp_enabled
|
||||
`
|
||||
|
||||
type RegisterWorkspaceProxyParams struct {
|
||||
Url string `db:"url" json:"url"`
|
||||
WildcardHostname string `db:"wildcard_hostname" json:"wildcard_hostname"`
|
||||
DerpEnabled bool `db:"derp_enabled" json:"derp_enabled"`
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) RegisterWorkspaceProxy(ctx context.Context, arg RegisterWorkspaceProxyParams) (WorkspaceProxy, error) {
|
||||
row := q.db.QueryRowContext(ctx, registerWorkspaceProxy, arg.Url, arg.WildcardHostname, arg.ID)
|
||||
row := q.db.QueryRowContext(ctx, registerWorkspaceProxy,
|
||||
arg.Url,
|
||||
arg.WildcardHostname,
|
||||
arg.DerpEnabled,
|
||||
arg.ID,
|
||||
)
|
||||
var i WorkspaceProxy
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
@ -3096,6 +3116,8 @@ func (q *sqlQuerier) RegisterWorkspaceProxy(ctx context.Context, arg RegisterWor
|
||||
&i.UpdatedAt,
|
||||
&i.Deleted,
|
||||
&i.TokenHashedSecret,
|
||||
&i.RegionID,
|
||||
&i.DerpEnabled,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -3118,7 +3140,7 @@ SET
|
||||
updated_at = Now()
|
||||
WHERE
|
||||
id = $5
|
||||
RETURNING id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret
|
||||
RETURNING id, name, display_name, icon, url, wildcard_hostname, created_at, updated_at, deleted, token_hashed_secret, region_id, derp_enabled
|
||||
`
|
||||
|
||||
type UpdateWorkspaceProxyParams struct {
|
||||
@ -3150,6 +3172,8 @@ func (q *sqlQuerier) UpdateWorkspaceProxy(ctx context.Context, arg UpdateWorkspa
|
||||
&i.UpdatedAt,
|
||||
&i.Deleted,
|
||||
&i.TokenHashedSecret,
|
||||
&i.RegionID,
|
||||
&i.DerpEnabled,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -3230,8 +3254,32 @@ func (q *sqlQuerier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt
|
||||
return err
|
||||
}
|
||||
|
||||
const getReplicaByID = `-- name: GetReplicaByID :one
|
||||
SELECT id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary" FROM replicas WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetReplicaByID(ctx context.Context, id uuid.UUID) (Replica, error) {
|
||||
row := q.db.QueryRowContext(ctx, getReplicaByID, id)
|
||||
var i Replica
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.StartedAt,
|
||||
&i.StoppedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Hostname,
|
||||
&i.RegionID,
|
||||
&i.RelayAddress,
|
||||
&i.DatabaseLatency,
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getReplicasUpdatedAfter = `-- name: GetReplicasUpdatedAfter :many
|
||||
SELECT id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error FROM replicas WHERE updated_at > $1 AND stopped_at IS NULL
|
||||
SELECT id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary" FROM replicas WHERE updated_at > $1 AND stopped_at IS NULL
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Time) ([]Replica, error) {
|
||||
@ -3255,6 +3303,7 @@ func (q *sqlQuerier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time
|
||||
&i.DatabaseLatency,
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -3279,8 +3328,9 @@ INSERT INTO replicas (
|
||||
region_id,
|
||||
relay_address,
|
||||
version,
|
||||
database_latency
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error
|
||||
database_latency,
|
||||
"primary"
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary"
|
||||
`
|
||||
|
||||
type InsertReplicaParams struct {
|
||||
@ -3293,6 +3343,7 @@ type InsertReplicaParams struct {
|
||||
RelayAddress string `db:"relay_address" json:"relay_address"`
|
||||
Version string `db:"version" json:"version"`
|
||||
DatabaseLatency int32 `db:"database_latency" json:"database_latency"`
|
||||
Primary bool `db:"primary" json:"primary"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertReplica(ctx context.Context, arg InsertReplicaParams) (Replica, error) {
|
||||
@ -3306,6 +3357,7 @@ func (q *sqlQuerier) InsertReplica(ctx context.Context, arg InsertReplicaParams)
|
||||
arg.RelayAddress,
|
||||
arg.Version,
|
||||
arg.DatabaseLatency,
|
||||
arg.Primary,
|
||||
)
|
||||
var i Replica
|
||||
err := row.Scan(
|
||||
@ -3320,6 +3372,7 @@ func (q *sqlQuerier) InsertReplica(ctx context.Context, arg InsertReplicaParams)
|
||||
&i.DatabaseLatency,
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -3334,8 +3387,9 @@ UPDATE replicas SET
|
||||
hostname = $7,
|
||||
version = $8,
|
||||
error = $9,
|
||||
database_latency = $10
|
||||
WHERE id = $1 RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error
|
||||
database_latency = $10,
|
||||
"primary" = $11
|
||||
WHERE id = $1 RETURNING id, created_at, started_at, stopped_at, updated_at, hostname, region_id, relay_address, database_latency, version, error, "primary"
|
||||
`
|
||||
|
||||
type UpdateReplicaParams struct {
|
||||
@ -3349,6 +3403,7 @@ type UpdateReplicaParams struct {
|
||||
Version string `db:"version" json:"version"`
|
||||
Error string `db:"error" json:"error"`
|
||||
DatabaseLatency int32 `db:"database_latency" json:"database_latency"`
|
||||
Primary bool `db:"primary" json:"primary"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) UpdateReplica(ctx context.Context, arg UpdateReplicaParams) (Replica, error) {
|
||||
@ -3363,6 +3418,7 @@ func (q *sqlQuerier) UpdateReplica(ctx context.Context, arg UpdateReplicaParams)
|
||||
arg.Version,
|
||||
arg.Error,
|
||||
arg.DatabaseLatency,
|
||||
arg.Primary,
|
||||
)
|
||||
var i Replica
|
||||
err := row.Scan(
|
||||
@ -3377,6 +3433,7 @@ func (q *sqlQuerier) UpdateReplica(ctx context.Context, arg UpdateReplicaParams)
|
||||
&i.DatabaseLatency,
|
||||
&i.Version,
|
||||
&i.Error,
|
||||
&i.Primary,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -7,20 +7,22 @@ INSERT INTO
|
||||
name,
|
||||
display_name,
|
||||
icon,
|
||||
derp_enabled,
|
||||
token_hashed_secret,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted
|
||||
)
|
||||
VALUES
|
||||
($1, '', '', $2, $3, $4, $5, $6, $7, false) RETURNING *;
|
||||
($1, '', '', $2, $3, $4, $5, $6, $7, $8, false) RETURNING *;
|
||||
|
||||
-- name: RegisterWorkspaceProxy :one
|
||||
UPDATE
|
||||
workspace_proxies
|
||||
SET
|
||||
url = @url,
|
||||
wildcard_hostname = @wildcard_hostname,
|
||||
url = @url :: text,
|
||||
wildcard_hostname = @wildcard_hostname :: text,
|
||||
derp_enabled = @derp_enabled :: boolean,
|
||||
updated_at = Now()
|
||||
WHERE
|
||||
id = @id
|
||||
|
@ -1,6 +1,9 @@
|
||||
-- name: GetReplicasUpdatedAfter :many
|
||||
SELECT * FROM replicas WHERE updated_at > $1 AND stopped_at IS NULL;
|
||||
|
||||
-- name: GetReplicaByID :one
|
||||
SELECT * FROM replicas WHERE id = $1;
|
||||
|
||||
-- name: InsertReplica :one
|
||||
INSERT INTO replicas (
|
||||
id,
|
||||
@ -11,8 +14,9 @@ INSERT INTO replicas (
|
||||
region_id,
|
||||
relay_address,
|
||||
version,
|
||||
database_latency
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
|
||||
database_latency,
|
||||
"primary"
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
|
||||
|
||||
-- name: UpdateReplica :one
|
||||
UPDATE replicas SET
|
||||
@ -24,7 +28,8 @@ UPDATE replicas SET
|
||||
hostname = $7,
|
||||
version = $8,
|
||||
error = $9,
|
||||
database_latency = $10
|
||||
database_latency = $10,
|
||||
"primary" = $11
|
||||
WHERE id = $1 RETURNING *;
|
||||
|
||||
-- name: DeleteReplicasUpdatedBefore :exec
|
||||
|
@ -22,6 +22,7 @@ const (
|
||||
UniqueWorkspaceBuildParametersWorkspaceBuildIDNameKey UniqueConstraint = "workspace_build_parameters_workspace_build_id_name_key" // ALTER TABLE ONLY workspace_build_parameters ADD CONSTRAINT workspace_build_parameters_workspace_build_id_name_key UNIQUE (workspace_build_id, name);
|
||||
UniqueWorkspaceBuildsJobIDKey UniqueConstraint = "workspace_builds_job_id_key" // ALTER TABLE ONLY workspace_builds ADD CONSTRAINT workspace_builds_job_id_key UNIQUE (job_id);
|
||||
UniqueWorkspaceBuildsWorkspaceIDBuildNumberKey UniqueConstraint = "workspace_builds_workspace_id_build_number_key" // ALTER TABLE ONLY workspace_builds ADD CONSTRAINT workspace_builds_workspace_id_build_number_key UNIQUE (workspace_id, build_number);
|
||||
UniqueWorkspaceProxiesRegionIDUnique UniqueConstraint = "workspace_proxies_region_id_unique" // ALTER TABLE ONLY workspace_proxies ADD CONSTRAINT workspace_proxies_region_id_unique UNIQUE (region_id);
|
||||
UniqueWorkspaceResourceMetadataName UniqueConstraint = "workspace_resource_metadata_name" // ALTER TABLE ONLY workspace_resource_metadata ADD CONSTRAINT workspace_resource_metadata_name UNIQUE (workspace_resource_id, key);
|
||||
UniqueIndexApiKeyName UniqueConstraint = "idx_api_key_name" // CREATE UNIQUE INDEX idx_api_key_name ON api_keys USING btree (user_id, token_name) WHERE (login_type = 'token'::login_type);
|
||||
UniqueIndexOrganizationName UniqueConstraint = "idx_organization_name" // CREATE UNIQUE INDEX idx_organization_name ON organizations USING btree (name);
|
||||
|
Reference in New Issue
Block a user