Compare commits

..

3 Commits

3 changed files with 96 additions and 55 deletions

View File

@ -218,57 +218,3 @@ services:
- frontend
restart: unless-stopped
{{< /highlight >}}
## Example with Caddy v2 as proxy
You will need the following `Caddyfile` on your host (or elsewhere, but then you'd need to adjust the proxy mount at the bottom of the compose file):
{{< highlight conf >}}
vikunja.example.com {
reverse_proxy /api/* api:3456
reverse_proxy frontend:80
}
{{< /highlight >}}
`docker-compose.yml` config:
{{< highlight yaml >}}
version: '3'
services:
db:
image: mariadb:10
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: vikunja
volumes:
- ./db:/var/lib/mysql
restart: unless-stopped
api:
image: vikunja/api
environment:
VIKUNJA_DATABASE_HOST: db
VIKUNJA_DATABASE_PASSWORD: supersecret
VIKUNJA_DATABASE_TYPE: mysql
VIKUNJA_DATABASE_USER: root
VIKUNJA_DATABASE_DATABASE: vikunja
volumes:
- ./files:/app/vikunja/files
depends_on:
- db
restart: unless-stopped
frontend:
image: vikunja/frontend
restart: unless-stopped
caddy:
image: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
depends_on:
- api
- frontend
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
{{< /highlight >}}

View File

@ -61,12 +61,14 @@ func CreateDBEngine() (engine *xorm.Engine, err error) {
if err != nil {
return
}
} else {
} else if config.DatabaseType.GetString() == "sqlite" {
// Otherwise use sqlite
engine, err = initSqliteEngine()
if err != nil {
return
}
} else {
log.Fatalf("Unknown database type %s", config.DatabaseType.GetString())
}
engine.SetMapper(core.GonicMapper{})

View File

@ -0,0 +1,93 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package migration
import (
"fmt"
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
func init() {
migrations = append(migrations, &xormigrate.Migration{
ID: "20200621214452",
Description: "Make all dates to iso time",
Migrate: func(tx *xorm.Engine) error {
convertTime := func(table, column string) error {
var sql string
switch tx.Dialect().URI().DBType {
case schemas.POSTGRES:
sql = `
ALTER TABLE ` + table + ` DROP COLUMN IF EXISTS ` + column + `_ts;
ALTER TABLE ` + table + ` ADD COLUMN ` + column + `_ts TIMESTAMP WITHOUT TIME ZONE NULL;
UPDATE ` + table + ` SET ` + column + `_ts = TIMESTAMP 'epoch' + ` + column + ` * INTERVAL '1 second';
ALTER TABLE ` + table + ` ALTER COLUMN ` + column + ` TYPE TIMESTAMP USING ` + column + `_ts;
ALTER TABLE ` + table + ` DROP COLUMN ` + column + `_ts;
`
case schemas.MYSQL:
sql = `
ALTER TABLE ` + table + ` DROP COLUMN IF EXISTS ` + column + `_ts;
ALTER TABLE ` + table + ` ADD ` + column + `_ts DATETIME null;
UPDATE ` + table + ` SET ` + column + `_ts = FROM_UNIXTIME(` + column + `);
ALTER TABLE ` + table + ` DROP COLUMN ` + column + `;
ALTER TABLE ` + table + ` CHANGE ` + column + `_ts ` + column + ` DATETIME NOT NULL;
`
case schemas.SQLITE:
// welp
default:
return fmt.Errorf("unsupported dbms: %s", tx.Dialect().URI().DBType)
}
sess := tx.NewSession()
if err := sess.Begin(); err != nil {
return err
}
_, err := sess.Exec(sql)
if err != nil {
_ = sess.Rollback()
return err
}
if err := sess.Commit(); err != nil {
return err
}
return nil
}
for table, columns := range map[string][]string{
"buckets": {
"created",
"updated",
},
} {
for _, column := range columns {
if err := convertTime(table, column); err != nil {
return err
}
}
}
return nil
},
Rollback: func(tx *xorm.Engine) error {
return nil
},
})
}