Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
id
usermetadb
Commits
d5fd9a28
Commit
d5fd9a28
authored
Jun 10, 2019
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow adding logs without a DeviceInfo field
parent
d324639f
Pipeline
#3358
passed with stages
in 5 minutes and 39 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
4 deletions
+116
-4
migrations/3_userlog_device_nullable.up.sql
migrations/3_userlog_device_nullable.up.sql
+31
-0
migrations/bindata.go
migrations/bindata.go
+55
-4
server/userlog_test.go
server/userlog_test.go
+30
-0
No files found.
migrations/3_userlog_device_nullable.up.sql
0 → 100644
View file @
d5fd9a28
-- Make the userlog.device_id field nullable. Unfortunately SQLite
-- does not support modifying constraints on a column, so we have to
-- dump and reload the table contents using a temporary table.
PRAGMA
foreign_keys
=
off
;
ALTER
TABLE
userlog
RENAME
TO
_userlog_old
;
CREATE
TABLE
userlog
(
username
TEXT
NOT
NULL
,
service
TEXT
NOT
NULL
,
log_type
TEXT
NOT
NULL
,
login_method
TEXT
,
message
TEXT
,
device_id
VARCHAR
(
64
),
device_remote_zone
TEXT
,
device_user_agent
TEXT
,
device_browser
TEXT
,
device_os
TEXT
,
device_mobile
BOOL
,
timestamp
DATETIME
);
INSERT
INTO
userlog
(
username
,
service
,
log_type
,
login_method
,
message
,
device_id
,
device_remote_zone
,
device_user_agent
,
device_browser
,
device_os
,
device_mobile
,
timestamp
)
SELECT
username
,
service
,
log_type
,
login_method
,
message
,
device_id
,
device_remote_zone
,
device_user_agent
,
device_browser
,
device_os
,
device_mobile
,
timestamp
FROM
_userlog_old
;
DROP
TABLE
_userlog_old
;
PRAGMA
foreign_keys
=
on
;
migrations/bindata.go
View file @
d5fd9a28
...
...
@@ -4,6 +4,7 @@
// migrations/1_initialize_schema.up.sql
// migrations/2_lastlogin.down.sql
// migrations/2_lastlogin.up.sql
// migrations/3_userlog_device_nullable.up.sql
// DO NOT EDIT!
package
migrations
...
...
@@ -65,7 +66,7 @@ func _1_initialize_schemaDownSql() (*asset, error) {
return
nil
,
err
}
info
:=
bindataFileInfo
{
name
:
"1_initialize_schema.down.sql"
,
size
:
144
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
4912747
1
,
0
)}
info
:=
bindataFileInfo
{
name
:
"1_initialize_schema.down.sql"
,
size
:
144
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
3501329
1
,
0
)}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
return
a
,
nil
}
...
...
@@ -121,7 +122,7 @@ func _1_initialize_schemaUpSql() (*asset, error) {
return
nil
,
err
}
info
:=
bindataFileInfo
{
name
:
"1_initialize_schema.up.sql"
,
size
:
1258
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
4912747
1
,
0
)}
info
:=
bindataFileInfo
{
name
:
"1_initialize_schema.up.sql"
,
size
:
1258
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
3501329
1
,
0
)}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
return
a
,
nil
}
...
...
@@ -141,7 +142,7 @@ func _2_lastloginDownSql() (*asset, error) {
return
nil
,
err
}
info
:=
bindataFileInfo
{
name
:
"2_lastlogin.down.sql"
,
size
:
100
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
49532976
,
0
)}
info
:=
bindataFileInfo
{
name
:
"2_lastlogin.down.sql"
,
size
:
100
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
51599549
,
0
)}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
return
a
,
nil
}
...
...
@@ -166,7 +167,55 @@ func _2_lastloginUpSql() (*asset, error) {
return
nil
,
err
}
info
:=
bindataFileInfo
{
name
:
"2_lastlogin.up.sql"
,
size
:
253
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
1549532906
,
0
)}
info
:=
bindataFileInfo
{
name
:
"2_lastlogin.up.sql"
,
size
:
253
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
1551599549
,
0
)}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
return
a
,
nil
}
var
__3_userlog_device_nullableUpSql
=
[]
byte
(
`
-- Make the userlog.device_id field nullable. Unfortunately SQLite
-- does not support modifying constraints on a column, so we have to
-- dump and reload the table contents using a temporary table.
PRAGMA foreign_keys=off;
ALTER TABLE userlog RENAME TO _userlog_old;
CREATE TABLE userlog (
username TEXT NOT NULL,
service TEXT NOT NULL,
log_type TEXT NOT NULL,
login_method TEXT,
message TEXT,
device_id VARCHAR(64),
device_remote_zone TEXT,
device_user_agent TEXT,
device_browser TEXT,
device_os TEXT,
device_mobile BOOL,
timestamp DATETIME
);
INSERT INTO userlog (username, service, log_type, login_method, message, device_id, device_remote_zone, device_user_agent, device_browser, device_os, device_mobile, timestamp)
SELECT username, service, log_type, login_method, message, device_id, device_remote_zone, device_user_agent, device_browser, device_os, device_mobile, timestamp
FROM _userlog_old;
DROP TABLE _userlog_old;
PRAGMA foreign_keys=on;
`
)
func
_3_userlog_device_nullableUpSqlBytes
()
([]
byte
,
error
)
{
return
__3_userlog_device_nullableUpSql
,
nil
}
func
_3_userlog_device_nullableUpSql
()
(
*
asset
,
error
)
{
bytes
,
err
:=
_3_userlog_device_nullableUpSqlBytes
()
if
err
!=
nil
{
return
nil
,
err
}
info
:=
bindataFileInfo
{
name
:
"3_userlog_device_nullable.up.sql"
,
size
:
1046
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
1560152262
,
0
)}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
return
a
,
nil
}
...
...
@@ -227,6 +276,7 @@ var _bindata = map[string]func() (*asset, error){
"1_initialize_schema.up.sql"
:
_1_initialize_schemaUpSql
,
"2_lastlogin.down.sql"
:
_2_lastloginDownSql
,
"2_lastlogin.up.sql"
:
_2_lastloginUpSql
,
"3_userlog_device_nullable.up.sql"
:
_3_userlog_device_nullableUpSql
,
}
// AssetDir returns the file names below a certain
...
...
@@ -273,6 +323,7 @@ var _bintree = &bintree{nil, map[string]*bintree{
"1_initialize_schema.up.sql"
:
&
bintree
{
_1_initialize_schemaUpSql
,
map
[
string
]
*
bintree
{}},
"2_lastlogin.down.sql"
:
&
bintree
{
_2_lastloginDownSql
,
map
[
string
]
*
bintree
{}},
"2_lastlogin.up.sql"
:
&
bintree
{
_2_lastloginUpSql
,
map
[
string
]
*
bintree
{}},
"3_userlog_device_nullable.up.sql"
:
&
bintree
{
_3_userlog_device_nullableUpSql
,
map
[
string
]
*
bintree
{}},
}}
// RestoreAsset restores an asset under the given directory
...
...
server/userlog_test.go
View file @
d5fd9a28
...
...
@@ -165,6 +165,36 @@ func TestUserlog_AddLog(t *testing.T) {
}
}
func
TestUserlog_AddLog_NoDeviceInfo
(
t
*
testing
.
T
)
{
defer
os
.
Remove
(
"test.db"
)
db
,
err
:=
openDB
(
"test.db"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
db
.
Close
()
ulog
,
err
:=
newUserlogDB
(
db
,
0
,
0
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
ulog
.
Close
()
// Create a LogEntry with a nil DeviceInfo.
u
:=
choose
(
randomUsernames
)
e
:=
&
usermetadb
.
LogEntry
{
Username
:
u
,
Service
:
choose
(
randomServices
),
Type
:
usermetadb
.
LogTypeLogin
,
LoginMethod
:
usermetadb
.
LoginMethodPassword
,
Message
:
"logged in"
,
Timestamp
:
randomTime
()
.
UTC
(),
}
if
err
:=
ulog
.
AddLog
(
e
);
err
!=
nil
{
t
.
Fatalf
(
"AddLog(%+v): %v"
,
e
,
err
)
}
}
func
TestUserlog_GetUserDevices
(
t
*
testing
.
T
)
{
defer
os
.
Remove
(
"test.db"
)
db
,
err
:=
openDB
(
"test.db"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment