Aneurin Barker Snook hai 10 meses
pai
achega
ef8ff4b25d
Modificáronse 4 ficheiros con 48 adicións e 5 borrados
  1. 11 0
      LICENSE.md
  2. 30 0
      README.md
  3. 6 4
      func_migration.go
  4. 1 1
      go.mod

+ 11 - 0
LICENSE.md

@@ -0,0 +1,11 @@
+# MIT License
+
+Copyright © 2024 Aneurin Barker Snook a@aneur.in
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+https://mit-license.org/

+ 30 - 0
README.md

@@ -0,0 +1,30 @@
+# Migres
+
+This package provides simple migration capabilities for any backend.
+
+## System requirements
+
+- [Go v1.21](https://go.dev/dl/)
+
+## Basic usage
+
+The key type in this package is `Module` which allows mapping [version strings](https://pkg.go.dev/github.com/annybs/go/version) to `Migration` interfaces. For example:
+
+```go
+import "github.com/annybs/migres"
+
+type MyBackend struct{}
+
+func (mb *MyBackend) Module() migres.Module {
+  return migres.Module{
+    "1.0.0": migres.Func(mb.upgradeV1, mb.downgradeV1),
+    "2.0.0": migres.Func(mb.upgradeV2, mb.downgradeV2),
+  }
+}
+```
+
+Call `Module.Upgrade(from, to)` or `Module.Downgrade(from, to)` in order to execute migrations. The module ensures migrations are all run in the correct order.
+
+## License
+
+See [LICENSE.md](./LICENSE.md)

+ 6 - 4
func_migration.go

@@ -2,12 +2,14 @@ package migres
 
 // FuncMigration enables creating a functional migration using callback functions.
 //
-//	type MyModule struct{}
+//	import "github.com/annybs/migres"
 //
-//	func Module() migres.Module {
+//	type MyBackend struct{}
+//
+//	func (mb *MyBackend) Module() migres.Module {
 //	  return migres.Module{
-//	    "1.0.0": migres.Func(MyModule.upgradeV1, MyModule.downgradeV1),
-//	    "2.0.0": migres.Func(MyModule.upgradeV2, MyModule.downgradeV2),
+//	    "1.0.0": migres.Func(mb.upgradeV1, mb.downgradeV1),
+//	    "2.0.0": migres.Func(mb.upgradeV2, mb.downgradeV2),
 //	  }
 //	}
 //

+ 1 - 1
go.mod

@@ -1,5 +1,5 @@
 module github.com/annybs/migres
 
-go 1.21.4
+go 1.21
 
 require github.com/annybs/go/version v0.0.0-20240715075456-18d811b39774