-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into no-protocol-redirect
- Loading branch information
Showing
30 changed files
with
738 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
views/apps/show.html | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package migrations | ||
|
||
import ( | ||
_ "embed" | ||
"log" | ||
|
||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
//go:embed initial_migration_postgres.sql | ||
var initialMigrationPostgres string | ||
//go:embed initial_migration_sqlite.sql | ||
var initialMigrationSqlite string | ||
|
||
var initialMigrations = map[string]string { | ||
"postgres": initialMigrationPostgres, | ||
"sqlite": initialMigrationSqlite, | ||
} | ||
|
||
// Initial migration | ||
var _202309271616_initial_migration = &gormigrate.Migration { | ||
ID: "202309271616_initial_migration", | ||
Migrate: func(tx *gorm.DB) error { | ||
// only execute migration if apps table doesn't exist | ||
err := tx.Exec("SELECT * FROM apps").Error; | ||
if err != nil { | ||
// find which initial migration should be executed | ||
initialMigration := initialMigrations[tx.Dialector.Name()] | ||
if initialMigration == "" { | ||
log.Fatalf("unsupported database type: %s", tx.Dialector.Name()) | ||
} | ||
|
||
return tx.Exec(initialMigration).Error | ||
} | ||
|
||
return nil | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
return nil; | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// Update payments with preimage as an empty string to use NULL instead | ||
var _202309271617_fix_preimage_null = &gormigrate.Migration { | ||
ID: "202309271617_fix_preimage_null", | ||
Migrate: func(tx *gorm.DB) error { | ||
return tx.Table("payments").Where("preimage = ?", "").Update("preimage", nil).Error; | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
return nil; | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package migrations | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// Create a composite index to improve performance of summing payments in the current budget period | ||
var _202309271618_add_payment_sum_index = &gormigrate.Migration { | ||
ID: "202309271618_add_payment_sum_index", | ||
Migrate: func(tx *gorm.DB) error { | ||
|
||
var sql string | ||
if tx.Dialector.Name() == "postgres" { | ||
sql = "CREATE INDEX idx_payment_sum ON payments USING btree (app_id, preimage, created_at) INCLUDE(amount)" | ||
} else if tx.Dialector.Name() == "sqlite" { | ||
sql = "CREATE INDEX idx_payment_sum ON payments (app_id, preimage, created_at)" | ||
} else { | ||
log.Fatalf("unsupported database type: %s", tx.Dialector.Name()) | ||
} | ||
|
||
return tx.Exec(sql).Error | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
return nil; | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Creating a new migration | ||
|
||
1. Create a new file based on the current date and time (see existing migration format) | ||
2. Copy the following code and update MY_ID_HERE and MY_COMMENT_HERE and DO_SOMETHING_HERE | ||
3. Add the ID to the list of migrations in migrate.go | ||
4. If possible, add a rollback function. | ||
|
||
*For Postgres/Sqlite specific migrations, see the [initial migration](202309271616.go)* | ||
|
||
```go | ||
package migrations | ||
|
||
import ( | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// MY_COMMENT_HERE | ||
var _MY_ID_HERE = &gormigrate.Migration { | ||
ID: "MY_ID_HERE", | ||
Migrate: func(tx *gorm.DB) error { | ||
return DO_SOMETHING_HERE.Error; | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
return nil; | ||
}, | ||
} | ||
``` |
Oops, something went wrong.