Skip to content

Commit

Permalink
last touches
Browse files Browse the repository at this point in the history
  • Loading branch information
peeperklip committed Feb 26, 2023
1 parent 0c94ac1 commit 11dd077
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# Migration
## Ignore for now as it's not production ready

Initially started within a separate project of mine because of a desire for a migration tool
[See commit and message 06048d639eee4c994544091f0e8b4a255c021554](https://github.com/peeperklip/migration/commit/06048d639eee4c994544091f0e8b4a255c021554) From there on its restructuring, testing and developing

Made public for my own testing/developing purposes as it's slightly less of a hassle to `go get` a public repository. Canges and features are made if i require them in my own projects

### Go get
```shell
go get https://github.com/peeperklip/migration@{COMMIT_HASH}
go get https://github.com/peeperklip/migration@0.0.1
# add the -u flag for updating
```

Expand All @@ -18,29 +12,31 @@ go get https://github.com/peeperklip/migration@{COMMIT_HASH}
* as per https://github.com/golang-standards/project-layout/tree/master/cmd
3. create a file + function that you can exectute command line
```
//Exexute in: $PROJECT_ROOT
//File: $PROJECT_ROOT/cli/migration.go
//Execute as:
func main() {
mig := migrations.NewMigration(
utils.CreateConnection(),
"postgress",
"..")
".")
migrations.Init(*mig)
}
```


### Architecture:
<b>main.go</b> Is the entry point for the CLI<br>
<b>app.go</b> Is the entry point for the CLI<br>
<b>dialect.go</b> Will eventually be used to support multiple SQL dialects<br>
<b>migration.go</b> Holds all the logic for managing migrations<br>
<b>dbUtils.go</b> In there to do more supporting tasks<br>

### Codestyle:
structs go first, interfaces second, then the methods, then general functions. Besides that it's pretty much just `gofmt .`

### To be improved
### To be improved in 0.0.2 and 0.0.3:
* The unsustainable swtich case in dialect.go
* The typejuggeling througout migration.go
* The last few methods in migration.go should be moved to its own file and struct
* Inject a logger
* unify output and make it swapable
* unify output and make more of the underlying code swapable
* general improvements throughout as well as a better distinction between exported and unexported methods
5 changes: 2 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ func Init(migrate migration) {
func outputHelpText() {
w := new(tabwriter.Writer)

// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
_, _ = fmt.Println("Usage: go cli/migrations.go [COMMAND]")
_, _ = fmt.Println()
_, _ = fmt.Println("Available commands:")
_, _ = fmt.Fprintln(w, "\tgenerate \t This generates a new migration")
_, _ = fmt.Fprintln(w, "\tmigrate \t Run the migrations")
_, _ = fmt.Fprintln(w, "\tdown \t Undo a specific migration according to down.sql")
_, _ = fmt.Fprintln(w, "\trevert \t Undo all migrations according to down.sql until, but >not< including the specified migration")
_, _ = fmt.Fprintln(w, "\tdown \t the last ran migration according to down.sql")
_, _ = fmt.Fprintln(w, "\trevert \t Revert to a specific migration")
_, _ = fmt.Fprintln(w, "\tstatus \t Warn about any migration that hasn't run")

_, _ = fmt.Fprintln(w)
Expand Down
9 changes: 0 additions & 9 deletions dbUtil.go

This file was deleted.

0 comments on commit 11dd077

Please sign in to comment.