Skip to content

Commit 4ad5bba

Browse files
committed
Remove JSON storage
1 parent 68e0456 commit 4ad5bba

16 files changed

Lines changed: 10 additions & 1011 deletions

File tree

garden-app/cmd/migrate.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

garden-app/cmd/root.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ func Execute() {
2525

2626
command.AddCommand(controllerCommand)
2727

28-
command.AddCommand(migrateCommand)
29-
30-
command.AddCommand(storageMigrateCommand)
31-
3228
viper.SetEnvPrefix("GARDEN_APP")
3329
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
3430
viper.AutomaticEnv()

garden-app/cmd/storage_migrate.go

Lines changed: 0 additions & 158 deletions
This file was deleted.

garden-app/config.yaml.example

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ influxdb:
1010
org: "garden"
1111
bucket: "garden"
1212
storage:
13-
driver: "hashmap"
13+
driver: "sqlite"
1414
options:
15-
filename: "gardens.yaml"
16-
# or use redis storage:
17-
# storage:
18-
# type: "KV"
19-
# options:
20-
# driver: "redis"
21-
# Server: "localhost:6379"
15+
data_source_name: "garden.db"

garden-app/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ require (
2626
github.com/spf13/cobra v1.8.1
2727
github.com/spf13/viper v1.17.0
2828
github.com/stretchr/testify v1.10.0
29-
github.com/tarmac-project/hord v0.6.0
30-
github.com/tarmac-project/hord/drivers/hashmap v0.6.0
31-
github.com/tarmac-project/hord/drivers/redis v0.6.0
3229
gopkg.in/dnaeon/go-vcr.v4 v4.0.1
3330
gopkg.in/yaml.v3 v3.0.1
3431
modernc.org/sqlite v1.46.1
@@ -127,6 +124,9 @@ require (
127124
github.com/spf13/pflag v1.0.5 // indirect
128125
github.com/stretchr/objx v0.5.2 // indirect
129126
github.com/subosito/gotenv v1.6.0 // indirect
127+
github.com/tarmac-project/hord v0.6.0 // indirect
128+
github.com/tarmac-project/hord/drivers/hashmap v0.6.0 // indirect
129+
github.com/tarmac-project/hord/drivers/redis v0.6.0 // indirect
130130
github.com/tdewolff/minify/v2 v2.12.9 // indirect
131131
github.com/tdewolff/parse/v2 v2.6.8 // indirect
132132
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect

garden-app/pkg/garden.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const (
1717
HealthStatusDown HealthStatus = "DOWN"
1818
HealthStatusUp HealthStatus = "UP"
1919
HealthStatusUnknown HealthStatus = "N/A"
20-
21-
currentGardenVersion = uint(2)
2220
)
2321

2422
// Garden is the representation of a single garden-controller device
@@ -34,7 +32,6 @@ type Garden struct {
3432
NotificationClientID *string `json:"notification_client_id,omitempty" yaml:"notification_client_id,omitempty"`
3533
NotificationSettings *NotificationSettings `json:"notification_settings,omitempty" yaml:"notification_settings,omitempty"`
3634
ControllerConfig *ControllerConfig `json:"controller_config,omitempty" yaml:"controller_config,omitempty"`
37-
Version uint `json:"version,omitempty" yaml:"version"`
3835
}
3936

4037
type NotificationSettings struct {
@@ -45,14 +42,6 @@ type NotificationSettings struct {
4542
WateringComplete bool `json:"watering_complete" yaml:"watering_complete"`
4643
}
4744

48-
func (g *Garden) GetVersion() uint {
49-
return g.Version
50-
}
51-
52-
func (g *Garden) SetVersion(v uint) {
53-
g.Version = v
54-
}
55-
5645
func (g *Garden) GetID() string {
5746
return g.ID.String()
5847
}
@@ -181,9 +170,6 @@ func (g *Garden) Bind(r *http.Request) error {
181170
g.CreatedAt = &now
182171
fallthrough
183172
case http.MethodPut:
184-
if g.Version == 0 {
185-
g.Version = currentGardenVersion
186-
}
187173
if g.CreatedAt == nil || g.CreatedAt.IsZero() {
188174
g.CreatedAt = &now
189175
}
@@ -267,7 +253,5 @@ func (g *Garden) Bind(r *http.Request) error {
267253
}
268254

269255
func (g *Garden) Render(_ http.ResponseWriter, _ *http.Request) error {
270-
// Version is excluded from responses because it's not important external information
271-
g.Version = 0
272256
return nil
273257
}

garden-app/pkg/storage/client.go

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import (
99
"github.com/calvinmclean/automated-garden/garden-app/pkg/weather"
1010

1111
"github.com/calvinmclean/babyapi"
12-
"github.com/calvinmclean/babyapi/storage/kv"
1312
"github.com/mitchellh/mapstructure"
14-
"github.com/tarmac-project/hord"
15-
"github.com/tarmac-project/hord/drivers/hashmap"
16-
"github.com/tarmac-project/hord/drivers/redis"
1713
)
1814

1915
// Config is used to identify and configure a storage client
@@ -40,17 +36,10 @@ type Client struct {
4036
}
4137

4238
func NewClient(config Config) (*Client, error) {
43-
switch config.Driver {
44-
case "sqlite":
45-
return newSQLiteClient(config)
46-
case "hashmap", "redis":
47-
return newKVClient(config)
48-
default:
49-
return nil, fmt.Errorf("invalid driver: %q", config.Driver)
39+
if config.Driver != "sqlite" {
40+
return nil, fmt.Errorf("invalid driver: %q (only sqlite is supported)", config.Driver)
5041
}
51-
}
5242

53-
func newSQLiteClient(config Config) (*Client, error) {
5443
var sqlConfig sql.Config
5544
err := mapstructure.Decode(config.Options, &sqlConfig)
5645
if err != nil {
@@ -72,52 +61,3 @@ func newSQLiteClient(config Config) (*Client, error) {
7261
AdditionalQueries: sqlClient.AdditionalQueries,
7362
}, nil
7463
}
75-
76-
func newKVClient(config Config) (*Client, error) {
77-
db, err := newHordDB(config)
78-
if err != nil {
79-
return nil, fmt.Errorf("error creating base client: %w", err)
80-
}
81-
82-
gardens := babyapi.NewKVStorage[*pkg.Garden](db, "Garden")
83-
zones := babyapi.NewKVStorage[*pkg.Zone](db, "Zone")
84-
waterSchedules := babyapi.NewKVStorage[*pkg.WaterSchedule](db, "WaterSchedule")
85-
86-
return &Client{
87-
Gardens: gardens,
88-
Zones: zones,
89-
WaterSchedules: waterSchedules,
90-
WeatherClientConfigs: babyapi.NewKVStorage[*weather.Config](db, "WeatherClient"),
91-
NotificationClientConfigs: babyapi.NewKVStorage[*notifications.Client](db, "NotificationClient"),
92-
WaterRoutines: babyapi.NewKVStorage[*pkg.WaterRoutine](db, "WaterRoutine"),
93-
AdditionalQueries: &KVAdditionalQueries{
94-
Gardens: gardens,
95-
Zones: zones,
96-
WaterSchedules: waterSchedules,
97-
},
98-
}, nil
99-
}
100-
101-
// newHordDB will create a new DB connection for one of the supported hord backends:
102-
// - hashmap
103-
// - redis
104-
func newHordDB(config Config) (hord.Database, error) {
105-
switch config.Driver {
106-
case "hashmap":
107-
var cfg hashmap.Config
108-
err := mapstructure.Decode(config.Options, &cfg)
109-
if err != nil {
110-
return nil, fmt.Errorf("error decoding config: %w", err)
111-
}
112-
return kv.NewFileDB(cfg)
113-
case "redis":
114-
var cfg redis.Config
115-
err := mapstructure.Decode(config.Options, &cfg)
116-
if err != nil {
117-
return nil, fmt.Errorf("error decoding config: %w", err)
118-
}
119-
return kv.NewRedisDB(cfg)
120-
default:
121-
return nil, fmt.Errorf("invalid KV driver: %q", config.Driver)
122-
}
123-
}

0 commit comments

Comments
 (0)