mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 23:15:57 +08:00
chore: add virtual fields table (#7586)
This commit is contained in:
parent
eed92978a4
commit
ba6f31b1c3
@ -51,6 +51,7 @@ func NewTestSqliteDB(t *testing.T) (sqlStore sqlstore.SQLStore, testDBFilePath s
|
|||||||
sqlmigration.NewUpdateDashboardAndSavedViewsFactory(sqlStore),
|
sqlmigration.NewUpdateDashboardAndSavedViewsFactory(sqlStore),
|
||||||
sqlmigration.NewUpdatePatAndOrgDomainsFactory(sqlStore),
|
sqlmigration.NewUpdatePatAndOrgDomainsFactory(sqlStore),
|
||||||
sqlmigration.NewUpdatePipelines(sqlStore),
|
sqlmigration.NewUpdatePipelines(sqlStore),
|
||||||
|
sqlmigration.NewAddVirtualFieldsFactory(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -69,6 +69,7 @@ func NewSQLMigrationProviderFactories(sqlstore sqlstore.SQLStore) factory.NamedM
|
|||||||
sqlmigration.NewUpdatePreferencesFactory(sqlstore),
|
sqlmigration.NewUpdatePreferencesFactory(sqlstore),
|
||||||
sqlmigration.NewUpdateApdexTtlFactory(sqlstore),
|
sqlmigration.NewUpdateApdexTtlFactory(sqlstore),
|
||||||
sqlmigration.NewUpdateResetPasswordFactory(sqlstore),
|
sqlmigration.NewUpdateResetPasswordFactory(sqlstore),
|
||||||
|
sqlmigration.NewAddVirtualFieldsFactory(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
pkg/sqlmigration/025_add_virtual_fields.go
Normal file
58
pkg/sqlmigration/025_add_virtual_fields.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package sqlmigration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/SigNoz/signoz/pkg/factory"
|
||||||
|
"github.com/SigNoz/signoz/pkg/types"
|
||||||
|
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
"github.com/uptrace/bun/migrate"
|
||||||
|
)
|
||||||
|
|
||||||
|
type addVirtualFields struct{}
|
||||||
|
|
||||||
|
func NewAddVirtualFieldsFactory() factory.ProviderFactory[SQLMigration, Config] {
|
||||||
|
return factory.NewProviderFactory(factory.MustNewName("add_virtual_fields"), newAddVirtualFields)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAddVirtualFields(_ context.Context, _ factory.ProviderSettings, _ Config) (SQLMigration, error) {
|
||||||
|
return &addVirtualFields{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (migration *addVirtualFields) Register(migrations *migrate.Migrations) error {
|
||||||
|
if err := migrations.Register(migration.Up, migration.Down); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (migration *addVirtualFields) Up(ctx context.Context, db *bun.DB) error {
|
||||||
|
// table:virtual_field op:create
|
||||||
|
if _, err := db.NewCreateTable().
|
||||||
|
Model(&struct {
|
||||||
|
bun.BaseModel `bun:"table:virtual_field"`
|
||||||
|
|
||||||
|
types.Identifiable
|
||||||
|
types.TimeAuditable
|
||||||
|
types.UserAuditable
|
||||||
|
|
||||||
|
Name string `bun:"name,type:text,notnull"`
|
||||||
|
Expression string `bun:"expression,type:text,notnull"`
|
||||||
|
Description string `bun:"description,type:text"`
|
||||||
|
Signal telemetrytypes.Signal `bun:"signal,type:text,notnull"`
|
||||||
|
OrgID string `bun:"org_id,type:text,notnull"`
|
||||||
|
}{}).
|
||||||
|
ForeignKey(`("org_id") REFERENCES "organizations" ("id") ON DELETE CASCADE`).
|
||||||
|
IfNotExists().
|
||||||
|
Exec(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (migration *addVirtualFields) Down(ctx context.Context, db *bun.DB) error {
|
||||||
|
return nil
|
||||||
|
}
|
21
pkg/types/telemetrytypes/virtualfield.go
Normal file
21
pkg/types/telemetrytypes/virtualfield.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package telemetrytypes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/SigNoz/signoz/pkg/types"
|
||||||
|
"github.com/SigNoz/signoz/pkg/valuer"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
)
|
||||||
|
|
||||||
|
type VirtualField struct {
|
||||||
|
bun.BaseModel `bun:"table:virtual_field"`
|
||||||
|
|
||||||
|
types.Identifiable
|
||||||
|
types.TimeAuditable
|
||||||
|
types.UserAuditable
|
||||||
|
|
||||||
|
Name string `bun:"name,type:text,notnull" json:"name"`
|
||||||
|
Expression string `bun:"expression,type:text,notnull" json:"expression"`
|
||||||
|
Description string `bun:"description,type:text" json:"description"`
|
||||||
|
Signal Signal `bun:"signal,type:text,notnull" json:"signal"`
|
||||||
|
OrgID valuer.UUID `bun:"org_id,type:text,notnull" json:"orgId"`
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user