mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
chore: Force license uuids to not be null (#6012)
* chore: Force license uuids to not be null * All unit tests generate uuids for licenses * Update migration files to new numbers * Put migration in transaction
This commit is contained in:
2
coderd/database/dump.sql
generated
2
coderd/database/dump.sql
generated
@ -211,7 +211,7 @@ CREATE TABLE licenses (
|
||||
uploaded_at timestamp with time zone NOT NULL,
|
||||
jwt text NOT NULL,
|
||||
exp timestamp with time zone NOT NULL,
|
||||
uuid uuid
|
||||
uuid uuid NOT NULL
|
||||
);
|
||||
|
||||
COMMENT ON COLUMN licenses.exp IS 'exp tracks the claim of the same name in the JWT, and we include it here so that we can easily query for licenses that have not yet expired.';
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE ONLY licenses ALTER COLUMN uuid DROP NOT NULL;
|
@ -0,0 +1,8 @@
|
||||
BEGIN;
|
||||
|
||||
-- We need to assign uuids to any existing licenses that don't have them.
|
||||
UPDATE licenses SET uuid = gen_random_uuid() WHERE uuid IS NULL;
|
||||
-- Assert no licenses have null uuids.
|
||||
ALTER TABLE ONLY licenses ALTER COLUMN uuid SET NOT NULL;
|
||||
|
||||
COMMIT;
|
@ -1288,8 +1288,8 @@ type License struct {
|
||||
UploadedAt time.Time `db:"uploaded_at" json:"uploaded_at"`
|
||||
JWT string `db:"jwt" json:"jwt"`
|
||||
// exp tracks the claim of the same name in the JWT, and we include it here so that we can easily query for licenses that have not yet expired.
|
||||
Exp time.Time `db:"exp" json:"exp"`
|
||||
Uuid uuid.NullUUID `db:"uuid" json:"uuid"`
|
||||
Exp time.Time `db:"exp" json:"exp"`
|
||||
UUID uuid.UUID `db:"uuid" json:"uuid"`
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
|
@ -1363,7 +1363,7 @@ func (q *sqlQuerier) GetLicenses(ctx context.Context) ([]License, error) {
|
||||
&i.UploadedAt,
|
||||
&i.JWT,
|
||||
&i.Exp,
|
||||
&i.Uuid,
|
||||
&i.UUID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1399,7 +1399,7 @@ func (q *sqlQuerier) GetUnexpiredLicenses(ctx context.Context) ([]License, error
|
||||
&i.UploadedAt,
|
||||
&i.JWT,
|
||||
&i.Exp,
|
||||
&i.Uuid,
|
||||
&i.UUID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1427,10 +1427,10 @@ VALUES
|
||||
`
|
||||
|
||||
type InsertLicenseParams struct {
|
||||
UploadedAt time.Time `db:"uploaded_at" json:"uploaded_at"`
|
||||
JWT string `db:"jwt" json:"jwt"`
|
||||
Exp time.Time `db:"exp" json:"exp"`
|
||||
Uuid uuid.NullUUID `db:"uuid" json:"uuid"`
|
||||
UploadedAt time.Time `db:"uploaded_at" json:"uploaded_at"`
|
||||
JWT string `db:"jwt" json:"jwt"`
|
||||
Exp time.Time `db:"exp" json:"exp"`
|
||||
UUID uuid.UUID `db:"uuid" json:"uuid"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertLicense(ctx context.Context, arg InsertLicenseParams) (License, error) {
|
||||
@ -1438,7 +1438,7 @@ func (q *sqlQuerier) InsertLicense(ctx context.Context, arg InsertLicenseParams)
|
||||
arg.UploadedAt,
|
||||
arg.JWT,
|
||||
arg.Exp,
|
||||
arg.Uuid,
|
||||
arg.UUID,
|
||||
)
|
||||
var i License
|
||||
err := row.Scan(
|
||||
@ -1446,7 +1446,7 @@ func (q *sqlQuerier) InsertLicense(ctx context.Context, arg InsertLicenseParams)
|
||||
&i.UploadedAt,
|
||||
&i.JWT,
|
||||
&i.Exp,
|
||||
&i.Uuid,
|
||||
&i.UUID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ overrides:
|
||||
troubleshooting_url: TroubleshootingURL
|
||||
default_ttl: DefaultTTL
|
||||
motd_file: MOTDFile
|
||||
uuid: UUID
|
||||
|
||||
sql:
|
||||
- schema: "./dump.sql"
|
||||
|
@ -645,7 +645,7 @@ func ConvertTemplateVersion(version database.TemplateVersion) TemplateVersion {
|
||||
func ConvertLicense(license database.License) License {
|
||||
return License{
|
||||
UploadedAt: license.UploadedAt,
|
||||
UUID: license.Uuid.UUID,
|
||||
UUID: license.UUID,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,10 +71,7 @@ func TestTelemetry(t *testing.T) {
|
||||
UploadedAt: database.Now(),
|
||||
JWT: "",
|
||||
Exp: database.Now().Add(time.Hour),
|
||||
Uuid: uuid.NullUUID{
|
||||
UUID: uuid.New(),
|
||||
Valid: true,
|
||||
},
|
||||
UUID: uuid.New(),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
_, snapshot := collectSnapshot(t, db)
|
||||
|
Reference in New Issue
Block a user