mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
rename last_quota_scan to last_quota_update
Existing databases must be updated using the script 20190728.sql
This commit is contained in:
parent
88fedd577d
commit
9987821003
9 changed files with 34 additions and 16 deletions
|
@ -11,7 +11,7 @@ env:
|
|||
- GO111MODULE=on
|
||||
|
||||
before_script:
|
||||
- sqlite3 sftpgo.db 'CREATE TABLE "users" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "username" varchar(255) NOT NULL UNIQUE, "password" varchar(255) NULL, "public_key" text NULL, "home_dir" varchar(255) NOT NULL, "uid" integer NOT NULL, "gid" integer NOT NULL, "max_sessions" integer NOT NULL, "quota_size" bigint NOT NULL, "quota_files" integer NOT NULL, "permissions" text NOT NULL, "used_quota_size" bigint NOT NULL, "used_quota_files" integer NOT NULL, "last_quota_scan" bigint NOT NULL, "upload_bandwidth" integer NOT NULL, "download_bandwidth" integer NOT NULL);'
|
||||
- sqlite3 sftpgo.db 'CREATE TABLE "users" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "username" varchar(255) NOT NULL UNIQUE, "password" varchar(255) NULL, "public_key" text NULL, "home_dir" varchar(255) NOT NULL, "uid" integer NOT NULL, "gid" integer NOT NULL, "max_sessions" integer NOT NULL, "quota_size" bigint NOT NULL, "quota_files" integer NOT NULL, "permissions" text NOT NULL, "used_quota_size" bigint NOT NULL, "used_quota_files" integer NOT NULL, "last_quota_update" bigint NOT NULL, "upload_bandwidth" integer NOT NULL, "download_bandwidth" integer NOT NULL);'
|
||||
|
||||
install:
|
||||
- go get -v -t ./...
|
||||
|
|
|
@ -54,7 +54,7 @@ The `sftpgo` executable supports the following command line flags:
|
|||
|
||||
Before starting `sftpgo` a dataprovider must be configured.
|
||||
|
||||
Sample SQL scripts to create the required database structure can be found insite the source tree [sql](https://github.com/drakkan/sftpgo/tree/master/sql "sql") directory.
|
||||
Sample SQL scripts to create the required database structure can be found insite the source tree [sql](https://github.com/drakkan/sftpgo/tree/master/sql "sql") directory. The SQL scripts filename's is, by convention, the date as `YYYYMMDD` and the suffix `.sql`. You need to apply all the SQL scripts for your database ordered by name, for example `20190706.sql` must be applied before `20190728.sql` and so on.
|
||||
|
||||
The `sftpgo.conf` configuration file contains the following sections:
|
||||
|
||||
|
|
|
@ -565,10 +565,10 @@ components:
|
|||
used_quota_file:
|
||||
type: integer
|
||||
format: int32
|
||||
last_quota_scan:
|
||||
last_quota_update:
|
||||
type: integer
|
||||
format: int64
|
||||
description: last quota scan as unix timestamp
|
||||
description: last quota update as unix timestamp in milliseconds
|
||||
upload_bandwidth:
|
||||
type: integer
|
||||
format: int32
|
||||
|
@ -588,7 +588,7 @@ components:
|
|||
start_time:
|
||||
type: integer
|
||||
format: int64
|
||||
description: start time as unix timestamp
|
||||
description: start time as unix timestamp in milliseconds
|
||||
size:
|
||||
type: integer
|
||||
format: int64
|
||||
|
@ -596,7 +596,7 @@ components:
|
|||
last_activity:
|
||||
type: integer
|
||||
format: int64
|
||||
description: last transfer activity as unix timestamp
|
||||
description: last transfer activity as unix timestamp in milliseconds
|
||||
ConnectionStatus:
|
||||
type: object
|
||||
properties:
|
||||
|
@ -615,11 +615,11 @@ components:
|
|||
connection_time:
|
||||
type: integer
|
||||
format: int64
|
||||
description: connection time as unix timestamp
|
||||
description: connection time as unix timestamp in milliseconds
|
||||
last_activity:
|
||||
type: integer
|
||||
format: int64
|
||||
description: last client activity as unix timestamp
|
||||
description: last client activity as unix timestamp in milliseconds
|
||||
active_transfers:
|
||||
type: array
|
||||
items:
|
||||
|
@ -633,7 +633,7 @@ components:
|
|||
start_time:
|
||||
type: integer
|
||||
format: int64
|
||||
description: scan start time as unix timestamp
|
||||
description: scan start time as unix timestamp in milliseconds
|
||||
ApiResponse:
|
||||
type: object
|
||||
properties:
|
||||
|
|
|
@ -240,12 +240,12 @@ func getUserFromDbRow(row *sql.Row, rows *sql.Rows) (User, error) {
|
|||
var err error
|
||||
if row != nil {
|
||||
err = row.Scan(&user.ID, &user.Username, &password, &publicKey, &user.HomeDir, &user.UID, &user.GID, &user.MaxSessions,
|
||||
&user.QuotaSize, &user.QuotaFiles, &permissions, &user.UsedQuotaSize, &user.UsedQuotaFiles, &user.LastQuotaScan,
|
||||
&user.QuotaSize, &user.QuotaFiles, &permissions, &user.UsedQuotaSize, &user.UsedQuotaFiles, &user.LastQuotaUpdate,
|
||||
&user.UploadBandwidth, &user.DownloadBandwidth)
|
||||
|
||||
} else {
|
||||
err = rows.Scan(&user.ID, &user.Username, &password, &publicKey, &user.HomeDir, &user.UID, &user.GID, &user.MaxSessions,
|
||||
&user.QuotaSize, &user.QuotaFiles, &permissions, &user.UsedQuotaSize, &user.UsedQuotaFiles, &user.LastQuotaScan,
|
||||
&user.QuotaSize, &user.QuotaFiles, &permissions, &user.UsedQuotaSize, &user.UsedQuotaFiles, &user.LastQuotaUpdate,
|
||||
&user.UploadBandwidth, &user.DownloadBandwidth)
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -4,7 +4,7 @@ import "fmt"
|
|||
|
||||
const (
|
||||
selectUserFields = "id,username,password,public_key,home_dir,uid,gid,max_sessions,quota_size,quota_files,permissions," +
|
||||
"used_quota_size,used_quota_files,last_quota_scan,upload_bandwidth,download_bandwidth"
|
||||
"used_quota_size,used_quota_files,last_quota_update,upload_bandwidth,download_bandwidth"
|
||||
)
|
||||
|
||||
func getSQLPlaceholders() []string {
|
||||
|
@ -38,10 +38,10 @@ func getUsersQuery(order string, username string) string {
|
|||
|
||||
func getUpdateQuotaQuery(reset bool) string {
|
||||
if reset {
|
||||
return fmt.Sprintf(`UPDATE %v SET used_quota_size = %v,used_quota_files = %v,last_quota_scan = %v
|
||||
return fmt.Sprintf(`UPDATE %v SET used_quota_size = %v,used_quota_files = %v,last_quota_update = %v
|
||||
WHERE username = %v`, config.UsersTable, sqlPlaceholders[0], sqlPlaceholders[1], sqlPlaceholders[2], sqlPlaceholders[3])
|
||||
}
|
||||
return fmt.Sprintf(`UPDATE %v SET used_quota_size = used_quota_size + %v,used_quota_files = used_quota_files + %v,last_quota_scan = %v
|
||||
return fmt.Sprintf(`UPDATE %v SET used_quota_size = used_quota_size + %v,used_quota_files = used_quota_files + %v,last_quota_update = %v
|
||||
WHERE username = %v`, config.UsersTable, sqlPlaceholders[0], sqlPlaceholders[1], sqlPlaceholders[2], sqlPlaceholders[3])
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ func getQuotaQuery() string {
|
|||
|
||||
func getAddUserQuery() string {
|
||||
return fmt.Sprintf(`INSERT INTO %v (username,password,public_key,home_dir,uid,gid,max_sessions,quota_size,quota_files,permissions,
|
||||
used_quota_size,used_quota_files,last_quota_scan,upload_bandwidth,download_bandwidth)
|
||||
used_quota_size,used_quota_files,last_quota_update,upload_bandwidth,download_bandwidth)
|
||||
VALUES (%v,%v,%v,%v,%v,%v,%v,%v,%v,%v,0,0,0,%v,%v)`, config.UsersTable, sqlPlaceholders[0], sqlPlaceholders[1],
|
||||
sqlPlaceholders[2], sqlPlaceholders[3], sqlPlaceholders[4], sqlPlaceholders[5], sqlPlaceholders[6], sqlPlaceholders[7],
|
||||
sqlPlaceholders[8], sqlPlaceholders[9], sqlPlaceholders[10], sqlPlaceholders[11])
|
||||
|
|
|
@ -34,7 +34,7 @@ type User struct {
|
|||
Permissions []string `json:"permissions"`
|
||||
UsedQuotaSize int64 `json:"used_quota_size"`
|
||||
UsedQuotaFiles int `json:"used_quota_files"`
|
||||
LastQuotaScan int64 `json:"last_quota_scan"`
|
||||
LastQuotaUpdate int64 `json:"last_quota_update"`
|
||||
UploadBandwidth int64 `json:"upload_bandwidth"`
|
||||
DownloadBandwidth int64 `json:"download_bandwidth"`
|
||||
}
|
||||
|
|
6
sql/mysql/20190728.sql
Normal file
6
sql/mysql/20190728.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
BEGIN;
|
||||
--
|
||||
-- Rename field last_quota_scan on user to last_quota_update
|
||||
--
|
||||
ALTER TABLE `users` CHANGE `last_quota_scan` `last_quota_update` bigint NOT NULL;
|
||||
COMMIT;
|
6
sql/pgsql/20190728.sql
Normal file
6
sql/pgsql/20190728.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
BEGIN;
|
||||
--
|
||||
-- Rename field last_quota_scan on user to last_quota_update
|
||||
--
|
||||
ALTER TABLE "users" RENAME COLUMN "last_quota_scan" TO "last_quota_update";
|
||||
COMMIT;
|
6
sql/sqlite/20190728.sql
Normal file
6
sql/sqlite/20190728.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
BEGIN;
|
||||
--
|
||||
-- Rename field last_quota_scan on user to last_quota_update
|
||||
--
|
||||
ALTER TABLE "users" RENAME COLUMN "last_quota_scan" TO "last_quota_update";
|
||||
COMMIT;
|
Loading…
Reference in a new issue