Compare commits
5 Commits
95a847d97c
...
3646aa0961
Author | SHA1 | Date |
---|---|---|
Erik Winter (aider) | 3646aa0961 | |
Erik Winter (aider) | fc2a0e32cf | |
Erik Winter | 7570f49581 | |
Erik Winter (aider) | e6c6dabb1b | |
Erik Winter | 4a71d685da |
3
Makefile
3
Makefile
|
@ -4,5 +4,8 @@ plan-deploy:
|
||||||
sync-run:
|
sync-run:
|
||||||
cd sync/service && go run . -dbname localhost -dbport 5432 -dbname planner -dbuser test -dbpassword test -port 8092 -key testKey
|
cd sync/service && go run . -dbname localhost -dbport 5432 -dbname planner -dbuser test -dbpassword test -port 8092 -key testKey
|
||||||
|
|
||||||
|
sync-debug:
|
||||||
|
cd sync/service && dlv debug . -- -dbname localhost -dbport 5432 -dbname planner -dbuser test -dbpassword test -port 8092 -key testKey
|
||||||
|
|
||||||
database:
|
database:
|
||||||
docker run -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=planner -p 5432:5432 postgres:16
|
docker run -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=planner -p 5432:5432 postgres:16
|
||||||
|
|
|
@ -12,12 +12,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
confPath, err := os.UserConfigDir()
|
confPath := os.Getenv("PLAN_CONFIG_PATH")
|
||||||
|
if confPath == "" {
|
||||||
|
userConfigDir, err := os.UserConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("could not get config path: %s\n", err)
|
fmt.Printf("could not get config path: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
conf, err := LoadConfig(filepath.Join(confPath, "planner", "plan", "config.yaml"))
|
confPath = filepath.Join(userConfigDir, "planner", "plan", "config.yaml")
|
||||||
|
}
|
||||||
|
conf, err := LoadConfig(confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("could not open config file: %s\n", err)
|
fmt.Printf("could not open config file: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -59,16 +59,18 @@ func NewPostgres(host, port, dbname, user, password string) (*Postgres, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Postgres) Update(i item.Item, ts time.Time) error {
|
func (p *Postgres) Update(i item.Item, ts time.Time) error {
|
||||||
var recurrerJSON []byte
|
var recurrerJSON any
|
||||||
var err error
|
|
||||||
if i.Recurrer != nil {
|
if i.Recurrer != nil {
|
||||||
|
var err error
|
||||||
recurrerJSON, err = json.Marshal(i.Recurrer)
|
recurrerJSON, err = json.Marshal(i.Recurrer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
recurrerJSON = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = p.db.Exec(`
|
_, err := p.db.Exec(`
|
||||||
INSERT INTO items (id, kind, updated, deleted, body, recurrer, recur_next)
|
INSERT INTO items (id, kind, updated, deleted, body, recurrer, recur_next)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
ON CONFLICT (id) DO UPDATE
|
ON CONFLICT (id) DO UPDATE
|
||||||
|
@ -111,13 +113,13 @@ func (p *Postgres) Updated(ks []item.Kind, t time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i item.Item
|
var i item.Item
|
||||||
var recurNext sql.NullTime
|
var recurNext sql.NullTime
|
||||||
var recurrerJSON []byte
|
var recurrerJSON sql.NullString
|
||||||
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
if len(recurrerJSON) > 0 {
|
if recurrerJSON.Valid && recurrerJSON.String != "" {
|
||||||
var recurrer item.Recur
|
var recurrer item.Recur
|
||||||
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
if err := json.Unmarshal([]byte(recurrerJSON.String), &recurrer); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
i.Recurrer = &recurrer
|
i.Recurrer = &recurrer
|
||||||
|
@ -147,13 +149,13 @@ func (p *Postgres) RecursBefore(date time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i item.Item
|
var i item.Item
|
||||||
var recurNext sql.NullTime
|
var recurNext sql.NullTime
|
||||||
var recurrerJSON []byte
|
var recurrerJSON sql.NullString
|
||||||
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
if len(recurrerJSON) > 0 {
|
if recurrerJSON.Valid && recurrerJSON.String != "" {
|
||||||
var recurrer item.Recur
|
var recurrer item.Recur
|
||||||
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
if err := json.Unmarshal([]byte(recurrerJSON.String), &recurrer); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
i.Recurrer = &recurrer
|
i.Recurrer = &recurrer
|
||||||
|
|
Loading…
Reference in New Issue