Skip to content

Commit

Permalink
add migrations for dashboards table
Browse files Browse the repository at this point in the history
  • Loading branch information
adelowo committed Feb 14, 2025
1 parent 2c02c1c commit 15c218b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 4 deletions.
1 change: 1 addition & 0 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ package malak
//go:generate mockgen -source=internal/pkg/billing/billing.go -destination=mocks/billing.go -package=malak_mocks
//go:generate mockgen -source=internal/secret/secret.go -destination=mocks/secret.go -package=malak_mocks
//go:generate mockgen -source=integration.go -destination=mocks/integration.go -package=malak_mocks
//go:generate mockgen -source=dashboard.go -destination=mocks/dashboard.go -package=malak_mocks
35 changes: 35 additions & 0 deletions internal/datastore/postgres/dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package postgres

import (
"context"
"database/sql"

"github.com/ayinke-llc/malak"
"github.com/uptrace/bun"
)

type dashboardRepo struct {
inner *bun.DB
}

func NewDashboardRepo(inner *bun.DB) malak.DashboardRepository {
return &dashboardRepo{
inner: inner,
}

Check warning on line 18 in internal/datastore/postgres/dashboard.go

View check run for this annotation

Codecov / codecov/patch

internal/datastore/postgres/dashboard.go#L15-L18

Added lines #L15 - L18 were not covered by tests
}

func (d *dashboardRepo) Create(ctx context.Context,
dashboard *malak.Dashboard) error {

ctx, cancelFn := withContext(ctx)
defer cancelFn()

return d.inner.RunInTx(ctx, &sql.TxOptions{},
func(ctx context.Context, tx bun.Tx) error {

_, err := tx.NewInsert().
Model(dashboard).
Exec(ctx)
return err
})

Check warning on line 34 in internal/datastore/postgres/dashboard.go

View check run for this annotation

Codecov / codecov/patch

internal/datastore/postgres/dashboard.go#L22-L34

Added lines #L22 - L34 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE dashboards
DROP COLUMN description,
DROP COLUMN chart_count,
DROP COLUMN created_at,
DROP COLUMN updated_at,
DROP COLUMN deleted_at;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE dashboards
ADD COLUMN description TEXT NOT NULL,
ADD COLUMN chart_count SMALLINT NOT NULL DEFAULT 0,
ADD COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN deleted_at TIMESTAMP WITH TIME ZONE;
56 changes: 56 additions & 0 deletions mocks/dashboard.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func GenerateReference(e EntityType) string {
// recipient_stat,recipient_log,
// deck,deck_preference, contact_share,dashboard,
// plan,price,integration,workspace_integration, integration_datapoint,
// integration_chart, integration_sync_checkpoint, dashboard)
// integration_chart, integration_sync_checkpoint)
type EntityType string

type Reference string
Expand Down
3 changes: 0 additions & 3 deletions reference_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15c218b

Please sign in to comment.