nidus-sync/db/jet/main.go
Eli Ribble 393836a86a
Fix notification of job happening before transaction is closed
This is kind of a wild one. Turns out that the triggers I was using
actually fire before the transaction is closed and I was primarily
getting lucky that the job was present on the other side of the
connection rather than having things built correctly.

I've fixed this by removing the trigger entirely and instead manually
triggering as part of the transaction. This makes the NOTIFY call happen
as soon as the transaction closes, just at the cost of making my
application be in charge of ensuring the NOTIFY gets called. Seems like
a win.

Part of doing this is porting the existing job creation code over to use
Jet. It's something I want to do anyway, so it's a win all around.
2026-05-22 23:34:38 +00:00

88 lines
3 KiB
Go

package main
import (
//"database/sql"
"log"
"os"
"github.com/Gleipnir-Technology/jet/generator/metadata"
genpostgres "github.com/Gleipnir-Technology/jet/generator/postgres"
"github.com/Gleipnir-Technology/jet/generator/template"
"github.com/Gleipnir-Technology/jet/postgres"
_ "github.com/lib/pq"
"github.com/twpayne/go-geom"
)
var schemas []string = []string{
"arcgis",
"comms",
"fileupload",
"public",
"publicreport",
"stadia",
}
func customTableSQLBuilderColumn(dialect template.Dialect, column metadata.Column) template.TableSQLBuilderColumn {
defaultColumn := template.DefaultTableSQLBuilderColumn(dialect, column)
/*
if defaultColumn.Name == "Location" {
log.Printf("current location column: name '%s' type '%s'", defaultColumn.Name, defaultColumn.Type)
defaultColumn.Import = "source.gleipnir.technology/Gleipnir/nidus-sync/db/column"
defaultColumn.PackageName = "column"
defaultColumn.Type = "ColumnGeometry"
defaultColumn.TypeFactory = "GeometryColumn"
}
*/
return defaultColumn
}
func customTableSQLBuilder(table metadata.Table) template.TableSQLBuilder {
builder := template.DefaultTableSQLBuilder(table).UseColumn(customTableSQLBuilderColumn)
log.Printf("table sql builder: path '%s' filename '%s' instancename '%s' typename '%s' defaultalias '%s'", builder.Path, builder.FileName, builder.InstanceName, builder.TypeName, builder.DefaultAlias)
builder.Imports = []string{"source.gleipnir.technology/Gleipnir/nidus-sync/db/column"}
return builder
}
func customTableModelField(column metadata.Column) template.TableModelField {
defaultTableModelField := template.DefaultTableModelField(column)
//log.Printf("'%s' '%s' '%s'", table.Name, column.Name, column.DataType.Name)
if column.Name == "extent" && column.DataType.Name == "box2d" {
defaultTableModelField.Type = template.NewType(geom.Bounds{})
} else if column.DataType.Name == "geometry" {
name := "geom.T"
if column.IsNullable {
name = "*geom.T"
}
geom_type := template.Type{
ImportPath: "github.com/twpayne/go-geom",
AdditionalImportPaths: []string{},
Name: name,
}
defaultTableModelField.Type = geom_type
}
return defaultTableModelField
}
func customTableModel(table metadata.Table) template.TableModel {
return template.DefaultTableModel(table).UseField(customTableModelField)
}
func customTemplate() template.Template {
return template.Default(postgres.Dialect).UseSchema(func(schema metadata.Schema) template.Schema {
customSchema := template.DefaultSchema(schema)
customSchema = customSchema.UseModel(template.DefaultModel().UseTable(customTableModel))
customSchema = customSchema.UseSQLBuilder(template.DefaultSQLBuilder().UseTable(customTableSQLBuilder))
return customSchema
})
}
func main() {
for _, schema := range schemas {
err := genpostgres.GenerateDSN(
"postgresql://?host=/var/run/postgresql&sslmode=disable&dbname=nidus-sync",
schema,
"../gen",
customTemplate(),
)
if err != nil {
log.Printf("Failed: %v", err)
os.Exit(1)
}
}
}