Skip to content

Commit 5a5f603

Browse files
committed
Add migration runner and compatibility docs
1 parent 55e14fe commit 5a5f603

15 files changed

Lines changed: 356 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1616
- Bulk delete API at `POST /admin/api/{resource}/bulk-delete` with de-duplicated ids and audit logging.
1717
- `pkg/adapters/sqlstore` for `database/sql` integrations, including MySQL and SQLite-style drivers.
1818
- `pkg/adapters/gormstore`, `pkg/adapters/mongostore`, and `pkg/adapters/redisstore`.
19+
- `pkg/migrate` SQL migration runner with ordered files and checksum tracking.
20+
- Compatibility policy and examples for existing chi, Gin/Echo, and GORM apps.
1921
- `docs/cli-init.md` for the supported init flags and generated project layout.
2022
- `docs/drop-in-adapters.md` for mounting GoMyAdmin on existing Go backends.
2123
- `docs/migrations.md` for versioned schema changes and release note expectations.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ pkg/
221221
cache/ tiny cache adapter contract + in-memory implementation
222222
filters/ search / sort / filter query parsing
223223
logger/ structured JSON logger (slog)
224+
migrate/ SQL migration runner with checksum tracking
224225
openapi/ OpenAPI 3.1 spec generation
225226
pagination/ page + per_page parsing
226227
postgres/ pgx connection pool + safe SQL query builder
@@ -630,6 +631,7 @@ The demo backend includes users, customers, invoices, invoice items, payments, t
630631
- [Authentication and sessions](docs/auth.md)
631632
- [Stable CLI init flow](docs/cli-init.md)
632633
- [Drop-in adapters for existing Go backends](docs/drop-in-adapters.md)
634+
- [Compatibility policy](docs/compatibility.md)
633635
- [Versioned migrations](docs/migrations.md)
634636
- [PostgreSQL CRM schema example](examples/postgres-crm/README.md)
635637

@@ -687,6 +689,7 @@ npm run build
687689
- [x] Generic `pkg/cache` interface for Redis/Memcached/application-cache adapters
688690
- [x] `database/sql` adapter for MySQL and SQLite-style drivers
689691
- [x] GORM, MongoDB, and Redis session adapters
692+
- [x] Production-oriented SQL migration runner with checksum tracking
690693
- [ ] Relation field rendering in the frontend
691694
- [ ] Playwright e2e tests for the CRM demo
692695

docs/compatibility.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Compatibility Policy
2+
3+
GoMyAdmin follows semantic versioning.
4+
5+
## Before v1.0.0
6+
7+
The project is still stabilizing. Minor releases may change public APIs when the change improves the long-term adapter model, security posture, or generated app structure.
8+
9+
Even before v1, GoMyAdmin tries to keep these stable:
10+
11+
- `pkg/admin` resource builder concepts
12+
- `pkg/server.Config`
13+
- `server.AdminStore`
14+
- `auth.SessionStore`
15+
- `storage.Storage`
16+
- generated API route shapes under `/admin/api`
17+
18+
## v1.0.0 and Later
19+
20+
After v1.0.0:
21+
22+
- breaking public API changes require a major version
23+
- adapters should remain source-compatible across minor releases
24+
- generated apps may receive new files, but existing generated code should keep compiling
25+
- database migrations are append-only
26+
27+
## Supported Runtime Targets
28+
29+
- Go: 1.23+
30+
- HTTP: any stack that can mount `http.Handler`
31+
- Built-in database adapter: PostgreSQL via pgx
32+
- Optional adapters: database/sql, MySQL-style SQL, SQLite-style SQL, GORM, MongoDB
33+
- Sessions: PostgreSQL, in-memory, cache-backed, Redis-backed
34+
- Storage: local filesystem, in-memory, S3-compatible

examples/existing-chi/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Existing chi App
2+
3+
```go
4+
package main
5+
6+
import (
7+
"context"
8+
"log"
9+
"net/http"
10+
"os"
11+
12+
"github.com/go-chi/chi/v5"
13+
"github.com/darwvin-dev/gomyadmin/pkg/admin"
14+
"github.com/darwvin-dev/gomyadmin/pkg/server"
15+
)
16+
17+
type User struct{}
18+
19+
func main() {
20+
app := admin.New("Acme Admin")
21+
app.Resource(User{}).
22+
TableName("users").
23+
Field("ID").String().Primary().Readonly().
24+
Field("Email").Email().Searchable().Sortable().
25+
Field("Status").Enum("active", "blocked").Filterable()
26+
27+
adminServer, err := server.New(context.Background(), server.Config{
28+
DatabaseURL: os.Getenv("DATABASE_URL"),
29+
App: app,
30+
Authenticate: func(ctx context.Context, email, password string) (admin.Actor, bool, error) {
31+
return admin.Actor{ID: "admin", Email: email, Roles: []string{"super_admin"}, Permissions: []string{"*"}}, true, nil
32+
},
33+
})
34+
if err != nil {
35+
log.Fatal(err)
36+
}
37+
defer adminServer.Close()
38+
39+
r := chi.NewRouter()
40+
r.Mount("/admin", http.StripPrefix("/admin", adminServer.Handler()))
41+
log.Fatal(http.ListenAndServe(":8080", r))
42+
}
43+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Existing Gin or Echo App
2+
3+
GoMyAdmin exposes a standard `http.Handler`, so frameworks can mount it through their HTTP adapter.
4+
5+
## Gin
6+
7+
```go
8+
adminHandler := adminServer.Handler()
9+
10+
router.Any("/admin/*path", func(c *gin.Context) {
11+
adminHandler.ServeHTTP(c.Writer, c.Request)
12+
})
13+
```
14+
15+
## Echo
16+
17+
```go
18+
adminHandler := adminServer.Handler()
19+
20+
e.Any("/admin/*", func(c echo.Context) error {
21+
adminHandler.ServeHTTP(c.Response(), c.Request())
22+
return nil
23+
})
24+
```
25+
26+
Use the same `server.Config` options shown in the chi example: pass either `DatabaseURL`, `Pool`, or a custom `Store`.

examples/gorm-store/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# GORM Store
2+
3+
```go
4+
gormDB, err := gorm.Open(mysql.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
5+
if err != nil {
6+
return err
7+
}
8+
9+
app := admin.New("Acme Admin")
10+
app.Resource(User{}).
11+
TableName("users").
12+
Field("ID").String().Primary().Readonly().
13+
Field("Email").Email().Searchable().Sortable()
14+
15+
store, err := gormstore.MySQL(gormDB, app)
16+
if err != nil {
17+
return err
18+
}
19+
20+
adminServer, err := server.New(ctx, server.Config{
21+
App: app,
22+
Store: store,
23+
SessionStore: redisstore.New(redisClient),
24+
Authenticate: authenticateAdmin,
25+
})
26+
```
27+
28+
The GORM adapter reuses GORM's underlying `*sql.DB`, so connection pooling and driver configuration stay owned by your app.

pkg/adapters/gormstore/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package gormstore adapts GORM-managed database connections to GoMyAdmin.
2+
package gormstore

pkg/adapters/mongostore/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package mongostore adapts MongoDB collections to GoMyAdmin resources.
2+
package mongostore

pkg/adapters/redisstore/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package redisstore provides Redis-backed auth.SessionStore construction.
2+
package redisstore

pkg/adapters/sqlstore/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Package sqlstore adapts database/sql connections to server.AdminStore.
2+
//
3+
// Use MySQL or SQLite helpers when your app already imports and configures the
4+
// relevant database/sql driver.
5+
package sqlstore

0 commit comments

Comments
 (0)