mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-09 15:15:08 +02:00
Add explicit DROP TABLE directives for temp_inactive_devices and drop the TEMP qualifier for non-postgres DBs, fixes #288
This commit is contained in:
@ -430,9 +430,16 @@ func (db *DB) GenerateAndStoreActiveUserStats(ctx context.Context) error {
|
|||||||
|
|
||||||
func (db *DB) SelfHostedDeepClean(ctx context.Context) error {
|
func (db *DB) SelfHostedDeepClean(ctx context.Context) error {
|
||||||
return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
|
supportsTempTable := db.Name() == "postgres"
|
||||||
|
tmpDirective := ""
|
||||||
|
if supportsTempTable {
|
||||||
|
tmpDirective = "TEMP"
|
||||||
|
}
|
||||||
runDeletes := os.Getenv("HISHTORY_SELF_HOSTED_DEEP_CLEAN") != ""
|
runDeletes := os.Getenv("HISHTORY_SELF_HOSTED_DEEP_CLEAN") != ""
|
||||||
|
_ = tx.Exec(`DROP TABLE IF EXISTS temp_inactive_devices`)
|
||||||
|
defer tx.Exec(`DROP TABLE IF EXISTS temp_inactive_devices`)
|
||||||
r := tx.Exec(`
|
r := tx.Exec(`
|
||||||
CREATE TEMP TABLE temp_inactive_devices AS (
|
CREATE ` + tmpDirective + ` TABLE temp_inactive_devices AS (
|
||||||
SELECT device_id
|
SELECT device_id
|
||||||
FROM usage_data
|
FROM usage_data
|
||||||
WHERE last_used <= (now() - INTERVAL '90 days')
|
WHERE last_used <= (now() - INTERVAL '90 days')
|
||||||
|
Reference in New Issue
Block a user