mirror of
https://github.com/1f349/orchid.git
synced 2025-02-05 14:06:40 +00:00
Change certificates.not_after and certificates.renew_retry to allow null values
This commit is contained in:
parent
c247a50472
commit
c373f18336
@ -1,6 +1,6 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// sqlc v1.25.0
|
// sqlc v1.28.0
|
||||||
// source: certificate.sql
|
// source: certificate.sql
|
||||||
|
|
||||||
package database
|
package database
|
||||||
@ -19,7 +19,7 @@ VALUES (?, ?, ?, ?)
|
|||||||
type AddCertificateParams struct {
|
type AddCertificateParams struct {
|
||||||
Owner string `json:"owner"`
|
Owner string `json:"owner"`
|
||||||
Dns sql.NullInt64 `json:"dns"`
|
Dns sql.NullInt64 `json:"dns"`
|
||||||
NotAfter time.Time `json:"not_after"`
|
NotAfter sql.NullTime `json:"not_after"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ FROM certificates AS cert
|
|||||||
WHERE cert.active = 1
|
WHERE cert.active = 1
|
||||||
AND (cert.auto_renew = 1 OR cert.not_after IS NULL)
|
AND (cert.auto_renew = 1 OR cert.not_after IS NULL)
|
||||||
AND cert.renewing = 0
|
AND cert.renewing = 0
|
||||||
AND DATETIME() > DATETIME(cert.renew_retry)
|
AND (cert.renew_retry IS NULL OR DATETIME() > DATETIME(cert.renew_retry))
|
||||||
AND (cert.not_after IS NULL OR DATETIME(cert.not_after, 'utc', '-30 days') < DATETIME())
|
AND (cert.not_after IS NULL OR DATETIME(cert.not_after, 'utc', '-30 days') < DATETIME())
|
||||||
ORDER BY cert.temp_parent, cert.not_after DESC NULLS FIRST
|
ORDER BY cert.temp_parent, cert.not_after DESC NULLS FIRST
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
@ -83,7 +83,7 @@ LIMIT 1
|
|||||||
|
|
||||||
type FindNextCertRow struct {
|
type FindNextCertRow struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
NotAfter time.Time `json:"not_after"`
|
NotAfter sql.NullTime `json:"not_after"`
|
||||||
Type sql.NullString `json:"type"`
|
Type sql.NullString `json:"type"`
|
||||||
Token sql.NullString `json:"token"`
|
Token sql.NullString `json:"token"`
|
||||||
TempParent sql.NullInt64 `json:"temp_parent"`
|
TempParent sql.NullInt64 `json:"temp_parent"`
|
||||||
@ -120,8 +120,8 @@ type FindOwnedCertsRow struct {
|
|||||||
AutoRenew bool `json:"auto_renew"`
|
AutoRenew bool `json:"auto_renew"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
Renewing bool `json:"renewing"`
|
Renewing bool `json:"renewing"`
|
||||||
RenewRetry time.Time `json:"renew_retry"`
|
RenewRetry sql.NullTime `json:"renew_retry"`
|
||||||
NotAfter time.Time `json:"not_after"`
|
NotAfter sql.NullTime `json:"not_after"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ WHERE id = ?
|
|||||||
`
|
`
|
||||||
|
|
||||||
type UpdateCertAfterRenewalParams struct {
|
type UpdateCertAfterRenewalParams struct {
|
||||||
NotAfter time.Time `json:"not_after"`
|
NotAfter sql.NullTime `json:"not_after"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ WHERE id = ?
|
|||||||
|
|
||||||
type UpdateRenewingStateParams struct {
|
type UpdateRenewingStateParams struct {
|
||||||
Renewing bool `json:"renewing"`
|
Renewing bool `json:"renewing"`
|
||||||
RenewRetry time.Time `json:"renew_retry"`
|
RenewRetry sql.NullTime `json:"renew_retry"`
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// sqlc v1.25.0
|
// sqlc v1.28.0
|
||||||
// source: certificate_domains.sql
|
// source: certificate_domains.sql
|
||||||
|
|
||||||
package database
|
package database
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// sqlc v1.25.0
|
// sqlc v1.28.0
|
||||||
|
|
||||||
package database
|
package database
|
||||||
|
|
||||||
|
29
database/migrations/20250131183447_null_not_after.up.sql
Normal file
29
database/migrations/20250131183447_null_not_after.up.sql
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-- null not after
|
||||||
|
|
||||||
|
ALTER TABLE certificates
|
||||||
|
RENAME COLUMN not_after TO not_after_2;
|
||||||
|
|
||||||
|
ALTER TABLE certificates
|
||||||
|
ADD COLUMN not_after DATETIME NULL;
|
||||||
|
|
||||||
|
UPDATE certificates
|
||||||
|
SET not_after = not_after_2
|
||||||
|
WHERE not_after IS NULL;
|
||||||
|
|
||||||
|
ALTER TABLE certificates
|
||||||
|
DROP COLUMN not_after_2;
|
||||||
|
|
||||||
|
-- null renew retry
|
||||||
|
|
||||||
|
ALTER TABLE certificates
|
||||||
|
RENAME COLUMN renew_retry TO renew_retry_2;
|
||||||
|
|
||||||
|
ALTER TABLE certificates
|
||||||
|
ADD COLUMN renew_retry DATETIME NULL;
|
||||||
|
|
||||||
|
UPDATE certificates
|
||||||
|
SET renew_retry = renew_retry_2
|
||||||
|
WHERE renew_retry IS NULL;
|
||||||
|
|
||||||
|
ALTER TABLE certificates
|
||||||
|
DROP COLUMN renew_retry_2;
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// sqlc v1.25.0
|
// sqlc v1.28.0
|
||||||
|
|
||||||
package database
|
package database
|
||||||
|
|
||||||
@ -16,10 +16,10 @@ type Certificate struct {
|
|||||||
AutoRenew bool `json:"auto_renew"`
|
AutoRenew bool `json:"auto_renew"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
Renewing bool `json:"renewing"`
|
Renewing bool `json:"renewing"`
|
||||||
NotAfter time.Time `json:"not_after"`
|
NotAfter sql.NullTime `json:"not_after"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
TempParent sql.NullInt64 `json:"temp_parent"`
|
TempParent sql.NullInt64 `json:"temp_parent"`
|
||||||
RenewRetry time.Time `json:"renew_retry"`
|
RenewRetry sql.NullTime `json:"renew_retry"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CertificateDomain struct {
|
type CertificateDomain struct {
|
||||||
|
@ -5,7 +5,7 @@ FROM certificates AS cert
|
|||||||
WHERE cert.active = 1
|
WHERE cert.active = 1
|
||||||
AND (cert.auto_renew = 1 OR cert.not_after IS NULL)
|
AND (cert.auto_renew = 1 OR cert.not_after IS NULL)
|
||||||
AND cert.renewing = 0
|
AND cert.renewing = 0
|
||||||
AND DATETIME() > DATETIME(cert.renew_retry)
|
AND (cert.renew_retry IS NULL OR DATETIME() > DATETIME(cert.renew_retry))
|
||||||
AND (cert.not_after IS NULL OR DATETIME(cert.not_after, 'utc', '-30 days') < DATETIME())
|
AND (cert.not_after IS NULL OR DATETIME(cert.not_after, 'utc', '-30 days') < DATETIME())
|
||||||
ORDER BY cert.temp_parent, cert.not_after DESC NULLS FIRST
|
ORDER BY cert.temp_parent, cert.not_after DESC NULLS FIRST
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
@ -292,7 +292,7 @@ func (s *Service) findNextCertificateToRenew() (*localCertData, error) {
|
|||||||
d.id = row.ID
|
d.id = row.ID
|
||||||
d.dns.name = row.Type
|
d.dns.name = row.Type
|
||||||
d.dns.token = row.Token
|
d.dns.token = row.Token
|
||||||
d.notAfter = row.NotAfter
|
d.notAfter = row.NotAfter.Time
|
||||||
d.tempParent = row.TempParent
|
d.tempParent = row.TempParent
|
||||||
|
|
||||||
return d, nil
|
return d, nil
|
||||||
@ -412,7 +412,7 @@ func (s *Service) renewCert(localData *localCertData) error {
|
|||||||
|
|
||||||
// set the NotAfter/NotBefore in the database
|
// set the NotAfter/NotBefore in the database
|
||||||
err = s.db.UpdateCertAfterRenewal(context.Background(), database.UpdateCertAfterRenewalParams{
|
err = s.db.UpdateCertAfterRenewal(context.Background(), database.UpdateCertAfterRenewalParams{
|
||||||
NotAfter: cert.NotAfter,
|
NotAfter: sql.NullTime{Time: cert.NotAfter, Valid: true},
|
||||||
UpdatedAt: cert.NotBefore,
|
UpdatedAt: cert.NotBefore,
|
||||||
ID: localData.id,
|
ID: localData.id,
|
||||||
})
|
})
|
||||||
|
@ -73,8 +73,8 @@ func NewApiServer(listen string, db *database.Queries, signer *mjwt.KeyStore, do
|
|||||||
AutoRenew: row.AutoRenew,
|
AutoRenew: row.AutoRenew,
|
||||||
Active: row.Active,
|
Active: row.Active,
|
||||||
Renewing: row.Renewing,
|
Renewing: row.Renewing,
|
||||||
RenewRetry: row.RenewRetry,
|
RenewRetry: row.RenewRetry.Time,
|
||||||
NotAfter: row.NotAfter,
|
NotAfter: row.NotAfter.Time,
|
||||||
UpdatedAt: row.UpdatedAt,
|
UpdatedAt: row.UpdatedAt,
|
||||||
}
|
}
|
||||||
d := row.Domain
|
d := row.Domain
|
||||||
@ -136,7 +136,7 @@ func NewApiServer(listen string, db *database.Queries, signer *mjwt.KeyStore, do
|
|||||||
err := db.AddCertificate(req.Context(), database.AddCertificateParams{
|
err := db.AddCertificate(req.Context(), database.AddCertificateParams{
|
||||||
Owner: b.Subject,
|
Owner: b.Subject,
|
||||||
Dns: sql.NullInt64{},
|
Dns: sql.NullInt64{},
|
||||||
NotAfter: time.Now(),
|
NotAfter: sql.NullTime{Time: time.Now(), Valid: true},
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user