rename last_quota_scan to last_quota_update

Existing databases must be updated using the script 20190728.sql
This commit is contained in:
Nicola Murino 2019-07-28 19:29:32 +02:00
parent 88fedd577d
commit 9987821003
9 changed files with 34 additions and 16 deletions

View file

@ -11,7 +11,7 @@ env:
- GO111MODULE=on - GO111MODULE=on
before_script: 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: install:
- go get -v -t ./... - go get -v -t ./...

View file

@ -54,7 +54,7 @@ The `sftpgo` executable supports the following command line flags:
Before starting `sftpgo` a dataprovider must be configured. 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: The `sftpgo.conf` configuration file contains the following sections:

View file

@ -565,10 +565,10 @@ components:
used_quota_file: used_quota_file:
type: integer type: integer
format: int32 format: int32
last_quota_scan: last_quota_update:
type: integer type: integer
format: int64 format: int64
description: last quota scan as unix timestamp description: last quota update as unix timestamp in milliseconds
upload_bandwidth: upload_bandwidth:
type: integer type: integer
format: int32 format: int32
@ -588,7 +588,7 @@ components:
start_time: start_time:
type: integer type: integer
format: int64 format: int64
description: start time as unix timestamp description: start time as unix timestamp in milliseconds
size: size:
type: integer type: integer
format: int64 format: int64
@ -596,7 +596,7 @@ components:
last_activity: last_activity:
type: integer type: integer
format: int64 format: int64
description: last transfer activity as unix timestamp description: last transfer activity as unix timestamp in milliseconds
ConnectionStatus: ConnectionStatus:
type: object type: object
properties: properties:
@ -615,11 +615,11 @@ components:
connection_time: connection_time:
type: integer type: integer
format: int64 format: int64
description: connection time as unix timestamp description: connection time as unix timestamp in milliseconds
last_activity: last_activity:
type: integer type: integer
format: int64 format: int64
description: last client activity as unix timestamp description: last client activity as unix timestamp in milliseconds
active_transfers: active_transfers:
type: array type: array
items: items:
@ -633,7 +633,7 @@ components:
start_time: start_time:
type: integer type: integer
format: int64 format: int64
description: scan start time as unix timestamp description: scan start time as unix timestamp in milliseconds
ApiResponse: ApiResponse:
type: object type: object
properties: properties:

View file

@ -240,12 +240,12 @@ func getUserFromDbRow(row *sql.Row, rows *sql.Rows) (User, error) {
var err error var err error
if row != nil { if row != nil {
err = row.Scan(&user.ID, &user.Username, &password, &publicKey, &user.HomeDir, &user.UID, &user.GID, &user.MaxSessions, 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) &user.UploadBandwidth, &user.DownloadBandwidth)
} else { } else {
err = rows.Scan(&user.ID, &user.Username, &password, &publicKey, &user.HomeDir, &user.UID, &user.GID, &user.MaxSessions, 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) &user.UploadBandwidth, &user.DownloadBandwidth)
} }
if err != nil { if err != nil {

View file

@ -4,7 +4,7 @@ import "fmt"
const ( const (
selectUserFields = "id,username,password,public_key,home_dir,uid,gid,max_sessions,quota_size,quota_files,permissions," + 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 { func getSQLPlaceholders() []string {
@ -38,10 +38,10 @@ func getUsersQuery(order string, username string) string {
func getUpdateQuotaQuery(reset bool) string { func getUpdateQuotaQuery(reset bool) string {
if reset { 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]) 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]) WHERE username = %v`, config.UsersTable, sqlPlaceholders[0], sqlPlaceholders[1], sqlPlaceholders[2], sqlPlaceholders[3])
} }
@ -52,7 +52,7 @@ func getQuotaQuery() string {
func getAddUserQuery() 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, 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], 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[2], sqlPlaceholders[3], sqlPlaceholders[4], sqlPlaceholders[5], sqlPlaceholders[6], sqlPlaceholders[7],
sqlPlaceholders[8], sqlPlaceholders[9], sqlPlaceholders[10], sqlPlaceholders[11]) sqlPlaceholders[8], sqlPlaceholders[9], sqlPlaceholders[10], sqlPlaceholders[11])

View file

@ -34,7 +34,7 @@ type User struct {
Permissions []string `json:"permissions"` Permissions []string `json:"permissions"`
UsedQuotaSize int64 `json:"used_quota_size"` UsedQuotaSize int64 `json:"used_quota_size"`
UsedQuotaFiles int `json:"used_quota_files"` UsedQuotaFiles int `json:"used_quota_files"`
LastQuotaScan int64 `json:"last_quota_scan"` LastQuotaUpdate int64 `json:"last_quota_update"`
UploadBandwidth int64 `json:"upload_bandwidth"` UploadBandwidth int64 `json:"upload_bandwidth"`
DownloadBandwidth int64 `json:"download_bandwidth"` DownloadBandwidth int64 `json:"download_bandwidth"`
} }

6
sql/mysql/20190728.sql Normal file
View 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
View 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
View 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;