Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
package store
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
)
|
|
|
|
// RemoveUnusedBootstrapCampus removes the pristine Campus and Domain created
|
|
// for a new standalone installation. It waits until another enabled Domain
|
|
// exists, so an enrolling instance remains administrable while approval is
|
|
// pending.
|
|
func (s *Store) RemoveUnusedBootstrapCampus() (bool, error) {
|
|
tx, err := s.DB.Begin()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
var campusID int64
|
|
var campusUUID string
|
|
err = tx.QueryRow(`
|
|
SELECT id, uuid
|
|
FROM campuses
|
|
WHERE name = 'default'
|
|
AND authority_mode = 'standalone'
|
|
AND fqdn = 'localhost'
|
|
LIMIT 1
|
|
`).Scan(&campusID, &campusUUID)
|
|
if err != nil {
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|
|
|
|
var otherDomains int
|
|
if err := tx.QueryRow(`
|
|
SELECT count(*)
|
|
FROM domains
|
|
WHERE campus_uuid != ? AND enabled = 1
|
|
`, campusUUID).Scan(&otherDomains); err != nil {
|
|
return false, err
|
|
}
|
|
if otherDomains == 0 {
|
|
return false, nil
|
|
}
|
|
|
|
var pathCount int
|
|
if err := tx.QueryRow(`
|
|
SELECT count(*)
|
|
FROM paths
|
|
WHERE domain_uuid IN (
|
|
SELECT uuid FROM domains WHERE campus_uuid = ?
|
|
)
|
|
`, campusUUID).Scan(&pathCount); err != nil {
|
|
return false, err
|
|
}
|
|
if pathCount != 0 {
|
|
return false, errors.New(
|
|
"default Campus has Paths and cannot be removed automatically",
|
|
)
|
|
}
|
|
|
|
if _, err := tx.Exec(`
|
|
DELETE FROM config
|
|
WHERE domain_uuid IN (
|
|
SELECT uuid FROM domains WHERE campus_uuid = ?
|
|
)
|
|
`, campusUUID); err != nil {
|
|
return false, err
|
|
}
|
|
if _, err := tx.Exec(`
|
|
DELETE FROM domains WHERE campus_uuid = ?
|
|
`, campusUUID); err != nil {
|
|
return false, err
|
|
}
|
|
if _, err := tx.Exec(`
|
|
DELETE FROM campuses WHERE id = ?
|
|
`, campusID); err != nil {
|
|
return false, err
|
|
}
|
|
if err := tx.Commit(); err != nil {
|
|
return false, err
|
|
}
|
|
return true, nil
|
|
}
|