diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index a0868803..ac888bdd 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -43,10 +43,6 @@ jobs: $DATE_TIME = ([datetime]::Now.ToUniversalTime().toString("yyyy-MM-ddTHH:mm:ssZ")) | Out-String go build -ldflags "-s -w -X github.com/drakkan/sftpgo/version.commit=$GIT_COMMIT -X github.com/drakkan/sftpgo/version.date=$DATE_TIME" -o sftpgo.exe - - name: Initialize data provider - run: ./sftpgo initprovider - shell: bash - - name: Run test cases using SQLite provider run: go test -v -p 1 -timeout 10m ./... -coverprofile=coverage.txt -covermode=atomic @@ -177,7 +173,6 @@ jobs: - name: Run tests using PostgreSQL provider run: | - ./sftpgo initprovider go test -v -p 1 -timeout 10m ./... -covermode=atomic env: SFTPGO_DATA_PROVIDER__DRIVER: postgresql @@ -189,7 +184,6 @@ jobs: - name: Run tests using MySQL provider run: | - ./sftpgo initprovider go test -v -p 1 -timeout 10m ./... -covermode=atomic env: SFTPGO_DATA_PROVIDER__DRIVER: mysql diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ca72d944..6e73cff4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -111,10 +111,6 @@ jobs: $DATE_TIME = ([datetime]::Now.ToUniversalTime().toString("yyyy-MM-ddTHH:mm:ssZ")) | Out-String go build -ldflags "-s -w -X github.com/drakkan/sftpgo/version.commit=$GIT_COMMIT -X github.com/drakkan/sftpgo/version.date=$DATE_TIME" -o sftpgo.exe - - name: Initialize data provider - run: ./sftpgo initprovider - shell: bash - - name: Get SFTPGo version id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} diff --git a/README.md b/README.md index 59881874..f21f79f3 100644 --- a/README.md +++ b/README.md @@ -96,9 +96,11 @@ Before starting the SFTPGo server, please ensure that the configured data provid SQL based data providers (SQLite, MySQL, PostgreSQL) require the creation of a database containing the required tables. Memory and bolt data providers do not require an initialization. -After configuring the data provider using the configuration file, you can create the required database structure using the `initprovider` command. -For SQLite provider, the `initprovider` command will auto create the database file, if missing, and the required tables. -For PostgreSQL and MySQL providers, you need to create the configured database, and the `initprovider` command will create the required tables. +For PostgreSQL and MySQL providers, you need to create the configured database. + +SFTPGo will attempt to automatically detect if the data privider has been initialized and if not, initialize it on startup. + +Alternately, you can create the required data provider structure yourself using the `initprovider` command. For example, you can simply execute the following command from the configuration directory: @@ -112,7 +114,7 @@ Take a look at the CLI usage to learn how to specify a different configuration f sftpgo initprovider --help ``` -After the initialization, the database structure will be automatically checked and updated, if required, at startup. +After the first initialization (manual or automatic), the database structure will be automatically checked and updated, if required, at startup. ## Tutorials diff --git a/dataprovider/dataprovider.go b/dataprovider/dataprovider.go index b8fb26be..89a97a58 100644 --- a/dataprovider/dataprovider.go +++ b/dataprovider/dataprovider.go @@ -383,6 +383,15 @@ func Initialize(cnf Config, basePath string) error { if err != nil { return err } + err = provider.initializeDatabase() + if err != nil && err != ErrNoInitRequired { + logger.WarnToConsole("Unable to initialize data provider: %v", err) + providerLog(logger.LevelWarn, "Unable to initialize data provider: %v", err) + return err + } + if err == nil { + logger.DebugToConsole("Data provider successfully initialized") + } err = provider.migrateDatabase() if err != nil { providerLog(logger.LevelWarn, "database migration error: %v", err)