Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init command and enhanced init-db #369

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Init command and enhanced init-db #369

wants to merge 3 commits into from

Conversation

MarcelGeo
Copy link
Contributor

@MarcelGeo MarcelGeo commented Feb 5, 2025

init command

$ flask init --help
Usage: flask init [OPTIONS]

  Initialize database if does not exist or -r is provided. Perform check of
  server configuration. Send statistics, respecting your setup.

Options:
  -e, --email TEXT  [required]
  -r, --recreate    Recreate database and admin user.
  --help            Show this message and exit.

Initialization of fresh server

flask init -e mm@mm.sk

The -e/--email option is required. This parameter is used for creating the admin user and sending a check email.

Several steps are performed by this command when a fresh server instance is initialized:

  • Create database tables.
  • Create SERVICE_ID in the mergin_info database table.
  • Create the admin user with a generated password.
  • Perform a server health check, which provides information about the correctness of the installation.
  • Send a check message to the email provided with the -e/--email parameter.
    *If COLLECT_STATISTICS is enabled, the command attempts to send statistics to MM servers.

Initialization of an already initialized server

The -r/--recreate option recreating database and admin user with new password from scratch.

flask init -r -e mm@mm.sk

# Database initialization

Creating database  [####################################]  100%
Tables created.

# Creating admin user. Copy generated password.

Admin user created. Please save generated password.
Username: admin
Password: MprbgLgBgCVQ
Email: mm@mm.sk

# Server health check

Mergin Maps version: 2024.5.3
Error: No base URL set. Please set MERGIN_BASE_URL environment variable
Database initialized properly
Error: Celery process not running properly. Configure celery worker and celery beat. This breaks also email sending from the system.

# Sending check email to specified email address mm@mm.sk.

Error: Sending emails is disabled. Please set MAIL_SUPPRESS_SEND=False to enable sending emails.

# Sending statistics.

Error: Celery process not running properly. Configure celery worker and celery beat. This breaks also email sending from the system.

init command with already initialized DB, without -r and disabled COLLECT_STATISTICS. It's just sending check email and perform health check.

flask init -e marcel.kocisek@gmail.com

# Server health check

Mergin Maps version: 1900.1.2
Error: No base URL set. Please set MERGIN_BASE_URL environment variable
Database initialized properly
Celery is running properly

# Sending check email to specified email address marcel.kocisek@gmail.com.

Error: Sending emails is disabled. Please set MAIL_SUPPRESS_SEND=False to enable sending emails.

init-db command

It's just creating new database and and new MerginInfo row with service id. It could be still used for development.

- it's using all commands available in server
Copy link
Contributor

@harminius harminius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, let me try it.

server/mergin/commands.py Show resolved Hide resolved
server/mergin/commands.py Show resolved Hide resolved
server/mergin/commands.py Show resolved Hide resolved
server/mergin/commands.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Feb 7, 2025

Pull Request Test Coverage Report for Build 13237930325

Details

  • 24 of 114 (21.05%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.9%) to 92.344%

Changes Missing Coverage Covered Lines Changed/Added Lines %
server/mergin/commands.py 24 114 21.05%
Totals Coverage Status
Change from base Build 13114400777: -0.9%
Covered Lines: 6706
Relevant Lines: 7262

💛 - Coveralls

Copy link
Contributor

@varmar05 varmar05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

fg="red",
),
_echo_error(
"No base URL set. Please set MERGIN_BASE_URL environment variable",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we also check contact_email variable? I'd maybe use it for admin/test email

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can, but it's not required variable - see docs https://merginmaps.com/docs/server/administer/environment/


tables = db.engine.table_names()
if not tables or recreate:
_init_db()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this recreate flag might be dangerous, shall we ask for user confirmation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

- use default value CONTACT_EMAIL for init
@MarcelGeo MarcelGeo requested a review from varmar05 February 10, 2025 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants