good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
chat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
tinode
chat
Commits
f5fdddcc
Commit
f5fdddcc
authored
2 years ago
by
or-else
Browse files
Options
Downloads
Patches
Plain Diff
fix root user handling in init-db
parent
fa5e599c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tinode-db/main.go
+19
-23
19 additions, 23 deletions
tinode-db/main.go
with
19 additions
and
23 deletions
tinode-db/main.go
+
19
−
23
View file @
f5fdddcc
...
...
@@ -250,16 +250,29 @@ func main() {
log
.
Fatalln
(
"Database not found."
)
}
log
.
Println
(
"Database not found. Creating."
)
err
=
store
.
Store
.
InitDb
(
config
.
StoreConfig
,
false
)
if
err
==
nil
{
log
.
Println
(
"Database successfully created."
)
}
}
else
if
strings
.
Contains
(
err
.
Error
(),
"Invalid database version"
)
{
msg
:=
"Wrong DB version: expected "
+
strconv
.
Itoa
(
adapterVersion
)
+
", got "
+
strconv
.
Itoa
(
databaseVersion
)
+
"."
if
*
reset
{
log
.
Println
(
msg
,
"Dropping and recreating the database."
)
log
.
Println
(
msg
,
"Reset Requested. Dropping and recreating the database."
)
err
=
store
.
Store
.
InitDb
(
config
.
StoreConfig
,
true
)
if
err
==
nil
{
log
.
Println
(
"Database successfully reset."
)
}
}
else
if
*
upgrade
{
if
databaseVersion
>
adapterVersion
{
log
.
Fatalln
(
msg
,
"Unable to upgrade: database has greater version than the adapter."
)
}
log
.
Println
(
msg
,
"Upgrading the database."
)
err
=
store
.
Store
.
UpgradeDb
(
config
.
StoreConfig
)
if
err
==
nil
{
log
.
Println
(
"Database successfully upgraded."
)
}
}
else
{
log
.
Fatalln
(
msg
,
"Use --reset to reset, --upgrade to upgrade."
)
}
...
...
@@ -267,34 +280,17 @@ func main() {
log
.
Fatalln
(
"Failed to init DB adapter:"
,
err
)
}
}
else
if
*
reset
{
log
.
Println
(
"Database reset requested"
)
}
else
{
log
.
Println
(
"Database exists, DB version is correct. All done."
)
os
.
Exit
(
0
)
}
if
*
upgrade
{
// Upgrade DB from one version to another.
err
=
store
.
Store
.
UpgradeDb
(
config
.
StoreConfig
)
if
err
==
nil
{
log
.
Println
(
"Database successfully upgraded."
)
}
}
else
{
// Reset or create DB
log
.
Println
(
"Reset requested. Dropping and recreating the database."
)
err
=
store
.
Store
.
InitDb
(
config
.
StoreConfig
,
true
)
if
err
==
nil
{
var
action
string
if
*
reset
{
action
=
"reset"
}
else
{
action
=
"initialized"
}
log
.
Println
(
"Database"
,
action
)
log
.
Println
(
"Database successfully reset."
)
}
}
else
{
log
.
Println
(
"Database exists, version is correct."
)
}
if
err
!=
nil
{
log
.
Fatalln
(
"Fail
ed to init DB
:"
,
err
)
log
.
Fatalln
(
"Fail
ure
:"
,
err
)
}
if
!*
upgrade
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment