2020-05-01 21:00:51 +02:00
|
|
|
/*
|
2022-11-11 05:49:16 +01:00
|
|
|
* Copyright © 2020 Musing Studio LLC.
|
2020-05-01 21:00:51 +02:00
|
|
|
*
|
|
|
|
* This file is part of WriteFreely.
|
|
|
|
*
|
|
|
|
* WriteFreely is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, included
|
|
|
|
* in the LICENSE file in this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package migrations
|
|
|
|
|
|
|
|
func optimizeDrafts(db *datastore) error {
|
|
|
|
t, err := db.Begin()
|
2020-05-06 20:08:25 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Rollback()
|
|
|
|
return err
|
|
|
|
}
|
2020-05-01 21:00:51 +02:00
|
|
|
|
2020-05-06 20:08:48 +02:00
|
|
|
if db.driverName == driverSQLite {
|
|
|
|
_, err = t.Exec(`CREATE INDEX key_owner_post_id ON posts (owner_id, id)`)
|
|
|
|
} else {
|
|
|
|
_, err = t.Exec(`ALTER TABLE posts ADD INDEX(owner_id, id)`)
|
|
|
|
}
|
2020-05-01 21:00:51 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Rollback()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = t.Commit()
|
|
|
|
if err != nil {
|
|
|
|
t.Rollback()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|