SimpleCloudNotifier/scnserver/cmd/dbhash/main.go

61 lines
1.9 KiB
Go
Raw Permalink Normal View History

2023-05-28 19:59:57 +02:00
package main
import (
"blackforestbytes.com/simplecloudnotifier/db/schema"
"context"
"database/sql"
2023-05-28 19:59:57 +02:00
"fmt"
"github.com/glebarez/go-sqlite"
2024-06-01 01:01:58 +02:00
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
2023-05-28 19:59:57 +02:00
"gogs.mikescher.com/BlackForestBytes/goext/sq"
"time"
)
func main() {
2024-06-01 01:01:58 +02:00
exerr.Init(exerr.ErrorPackageConfigInit{})
2024-09-20 23:50:34 +02:00
ctx, cancel := context.WithTimeout(context.Background(), 1011*time.Second)
2023-05-28 19:59:57 +02:00
defer cancel()
if !langext.InArray("sqlite3", sql.Drivers()) {
sqlite.RegisterAsSQLITE3()
}
2024-06-01 01:01:58 +02:00
2024-09-20 23:50:34 +02:00
for key, schemaObj := range langext.AsSortedBy(langext.MapToArr(schema.PrimarySchema), func(v langext.MapEntry[int, schema.Def]) int { return v.Key }) {
var h0 string
if key == 1 {
h0 = "N/A"
} else {
var err error
h0, err = sq.HashGoSqliteSchema(ctx, schemaObj.Value.SQL)
if err != nil {
h0 = "ERR"
}
}
2024-09-20 23:50:34 +02:00
fmt.Printf("PrimarySchema [%d] := %s%s\n", schemaObj.Key, h0, langext.Conditional(schemaObj.Key == schema.PrimarySchemaVersion, " (active)", ""))
}
2024-06-01 01:01:58 +02:00
2024-09-20 23:50:34 +02:00
fmt.Printf("\n")
for _, schemaObj := range langext.AsSortedBy(langext.MapToArr(schema.RequestsSchema), func(v langext.MapEntry[int, schema.Def]) int { return v.Key }) {
h0, err := sq.HashGoSqliteSchema(ctx, schemaObj.Value.SQL)
2023-05-28 19:59:57 +02:00
if err != nil {
h0 = "ERR"
}
2024-09-20 23:50:34 +02:00
fmt.Printf("RequestsSchema [%d] := %s%s\n", schemaObj.Key, h0, langext.Conditional(schemaObj.Key == schema.RequestsSchemaVersion, " (active)", ""))
2023-05-28 19:59:57 +02:00
}
2024-06-01 01:01:58 +02:00
2024-09-20 23:50:34 +02:00
fmt.Printf("\n")
for _, schemaObj := range langext.AsSortedBy(langext.MapToArr(schema.LogsSchema), func(v langext.MapEntry[int, schema.Def]) int { return v.Key }) {
h0, err := sq.HashGoSqliteSchema(ctx, schemaObj.Value.SQL)
2023-05-28 19:59:57 +02:00
if err != nil {
h0 = "ERR"
}
2024-09-20 23:50:34 +02:00
fmt.Printf("LogsSchema [%d] := %s%s\n", schemaObj.Key, h0, langext.Conditional(schemaObj.Key == schema.LogsSchemaVersion, " (active)", ""))
2023-05-28 19:59:57 +02:00
}
2024-06-01 01:01:58 +02:00
2024-09-20 23:50:34 +02:00
fmt.Printf("\n")
2023-05-28 19:59:57 +02:00
}