mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
* fork: own SigNoz platform deps under hanzoai, repath imports off upstream brand
Phase 1 of the full-fork mandate: eliminate upstream-branded SigNoz modules,
own them as public hanzoai forks, and repath all imports to hanzoai paths.
Owned deps (new public hanzoai forks, module renamed to hanzoai path):
github.com/SigNoz/signoz-otel-collector v0.144.3
-> github.com/hanzoai/signoz-otel-collector v0.144.6 (module renamed)
github.com/SigNoz/clickhouse-go-mock v0.14.0
-> github.com/hanzoai/clickhouse-go-mock v0.14.1 (module renamed)
github.com/SigNoz/govaluate v0.0.0-20240203125216-988004ccc7fd
-> github.com/hanzoai/govaluate v0.1.0 (module renamed)
github.com/SigNoz/expr (replace target for github.com/expr-lang/expr)
-> github.com/hanzoai/expr v1.17.8 (upstream module path preserved,
consumed via replace exactly like the prior SigNoz/expr fork)
In-repo repath: the vendored SigNoz source tree in pkg/, ee/, cmd/ is now
self-referenced as github.com/hanzoai/o11y/... instead of
github.com/SigNoz/signoz/... (1300+ import lines across 377 files), matching
the 750 files already on the hanzoai path. Zero SigNoz-branded module
references remain in go.mod or any .go import.
Generic ecosystem libraries (golang.org/x, google.golang.org, prometheus,
opentelemetry, gin, cobra, luxfi/*, etc.) are left untouched — only the
SigNoz platform fork is owned.
Pre-existing (NOT introduced here): origin/main does not `go build ./...`
because 22 packages are imported but absent from the vendored tree; 14 of
them (roletypes, grammar, cloudintegrations, resourcefilter, integrationtypes,
metricsexplorer, metrics_explorer, times, agg_rewrite, bucket_cache,
sqlitesqlstore, sqlschema/postgressqlschema, sqlstore/postgressqlstore,
cloudintegrations/services) exist in no upstream SigNoz version and must be
vendored into hanzoai/o11y from hanzoai/signoz@770f464f to finish. This
repath is orthogonal to that gap.
* docs(LLM.md): fork boundary map + pre-existing compile-gap inventory
---------
Co-authored-by: Hanzo Dev <[email protected]>
134 lines
3.4 KiB
Go
134 lines
3.4 KiB
Go
package sqlmigration
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/o11y/pkg/factory"
|
|
"github.com/hanzoai/o11y/pkg/sqlschema"
|
|
"github.com/hanzoai/o11y/pkg/sqlstore"
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/migrate"
|
|
)
|
|
|
|
type updatePlannedMaintenanceRule struct {
|
|
sqlstore sqlstore.SQLStore
|
|
sqlschema sqlschema.SQLSchema
|
|
}
|
|
|
|
type plannedMaintenanceRuleRow struct {
|
|
bun.BaseModel `bun:"table:planned_maintenance_rule"`
|
|
|
|
ID string `bun:"id"`
|
|
PlannedMaintenanceID string `bun:"planned_maintenance_id"`
|
|
RuleID string `bun:"rule_id"`
|
|
}
|
|
|
|
func NewUpdatePlannedMaintenanceRuleFactory(sqlstore sqlstore.SQLStore, sqlschema sqlschema.SQLSchema) factory.ProviderFactory[SQLMigration, Config] {
|
|
return factory.NewProviderFactory(
|
|
factory.MustNewName("update_planned_maintenance_rule"),
|
|
func(ctx context.Context, ps factory.ProviderSettings, c Config) (SQLMigration, error) {
|
|
return &updatePlannedMaintenanceRule{
|
|
sqlstore: sqlstore,
|
|
sqlschema: sqlschema,
|
|
}, nil
|
|
},
|
|
)
|
|
}
|
|
|
|
func (migration *updatePlannedMaintenanceRule) Register(migrations *migrate.Migrations) error {
|
|
if err := migrations.Register(migration.Up, migration.Down); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (migration *updatePlannedMaintenanceRule) Up(ctx context.Context, db *bun.DB) error {
|
|
table, _, err := migration.sqlschema.GetTable(ctx, sqlschema.TableName("planned_maintenance_rule"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := migration.sqlschema.ToggleFKEnforcement(ctx, db, false); err != nil {
|
|
return err
|
|
}
|
|
|
|
tx, err := db.BeginTx(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer func() {
|
|
_ = tx.Rollback()
|
|
}()
|
|
|
|
// Read all existing rows
|
|
var rows []*plannedMaintenanceRuleRow
|
|
err = tx.NewSelect().Model(&rows).Scan(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Drop the existing table
|
|
dropTableSQLs := migration.sqlschema.Operator().DropTable(table)
|
|
for _, sql := range dropTableSQLs {
|
|
if _, err := tx.ExecContext(ctx, string(sql)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
// Create the table fresh without CASCADE constraints
|
|
newTable := &sqlschema.Table{
|
|
Name: sqlschema.TableName("planned_maintenance_rule"),
|
|
Columns: []*sqlschema.Column{
|
|
{Name: "id", DataType: sqlschema.DataTypeText, Nullable: false},
|
|
{Name: "planned_maintenance_id", DataType: sqlschema.DataTypeText, Nullable: false},
|
|
{Name: "rule_id", DataType: sqlschema.DataTypeText, Nullable: false},
|
|
},
|
|
PrimaryKeyConstraint: &sqlschema.PrimaryKeyConstraint{
|
|
ColumnNames: []sqlschema.ColumnName{"id"},
|
|
},
|
|
ForeignKeyConstraints: []*sqlschema.ForeignKeyConstraint{
|
|
{
|
|
ReferencingColumnName: "planned_maintenance_id",
|
|
ReferencedTableName: "planned_maintenance",
|
|
ReferencedColumnName: "id",
|
|
},
|
|
{
|
|
ReferencingColumnName: "rule_id",
|
|
ReferencedTableName: "rule",
|
|
ReferencedColumnName: "id",
|
|
},
|
|
},
|
|
}
|
|
|
|
createTableSQLs := migration.sqlschema.Operator().CreateTable(newTable)
|
|
for _, sql := range createTableSQLs {
|
|
if _, err := tx.ExecContext(ctx, string(sql)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
// Re-insert the data
|
|
if len(rows) > 0 {
|
|
_, err = tx.NewInsert().Model(&rows).Exec(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if err := tx.Commit(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := migration.sqlschema.ToggleFKEnforcement(ctx, db, true); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (migration *updatePlannedMaintenanceRule) Down(ctx context.Context, db *bun.DB) error {
|
|
return nil
|
|
}
|