mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-29 06:32:00 +08:00

* fix: support multitenancy in org * fix: register and login working now * fix: changes to migration * fix: migrations run both on sqlite and postgres * fix: remove user flags from fe and be * fix: remove ingestion keys from update * fix: multitenancy support for apdex settings * fix: render ts for users correctly * fix: fix migration to run for new tenants * fix: clean up migrations * fix: address comments * Update pkg/sqlmigration/013_update_organization.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: fix build * fix: force invites with org id * Update pkg/query-service/auth/auth.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: address comments * fix: address comments * fix: provier with their own dialect * fix: update dialects * fix: remove unwanted change * Update pkg/query-service/app/http_handler.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: different files for types --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
90 lines
2.5 KiB
Go
90 lines
2.5 KiB
Go
package postgressqlstore
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/jackc/pgx/v5/stdlib"
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/dialect/pgdialect"
|
|
"go.signoz.io/signoz/pkg/factory"
|
|
"go.signoz.io/signoz/pkg/sqlstore"
|
|
)
|
|
|
|
type provider struct {
|
|
settings factory.ScopedProviderSettings
|
|
sqldb *sql.DB
|
|
bundb *sqlstore.BunDB
|
|
sqlxdb *sqlx.DB
|
|
dialect *PGDialect
|
|
}
|
|
|
|
func NewFactory(hookFactories ...factory.ProviderFactory[sqlstore.SQLStoreHook, sqlstore.Config]) factory.ProviderFactory[sqlstore.SQLStore, sqlstore.Config] {
|
|
return factory.NewProviderFactory(factory.MustNewName("postgres"), func(ctx context.Context, providerSettings factory.ProviderSettings, config sqlstore.Config) (sqlstore.SQLStore, error) {
|
|
hooks := make([]sqlstore.SQLStoreHook, len(hookFactories))
|
|
for i, hookFactory := range hookFactories {
|
|
hook, err := hookFactory.New(ctx, providerSettings, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
hooks[i] = hook
|
|
}
|
|
|
|
return New(ctx, providerSettings, config, hooks...)
|
|
})
|
|
}
|
|
|
|
func New(ctx context.Context, providerSettings factory.ProviderSettings, config sqlstore.Config, hooks ...sqlstore.SQLStoreHook) (sqlstore.SQLStore, error) {
|
|
settings := factory.NewScopedProviderSettings(providerSettings, "go.signoz.io/signoz/pkg/sqlstore/postgressqlstore")
|
|
|
|
pgConfig, err := pgxpool.ParseConfig(config.Postgres.DSN)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Set the maximum number of open connections
|
|
pgConfig.MaxConns = int32(config.Connection.MaxOpenConns)
|
|
|
|
// Use pgxpool to create a connection pool
|
|
pool, err := pgxpool.NewWithConfig(ctx, pgConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
sqldb := stdlib.OpenDBFromPool(pool)
|
|
|
|
return &provider{
|
|
settings: settings,
|
|
sqldb: sqldb,
|
|
bundb: sqlstore.NewBunDB(settings, sqldb, pgdialect.New(), hooks),
|
|
sqlxdb: sqlx.NewDb(sqldb, "postgres"),
|
|
dialect: &PGDialect{},
|
|
}, nil
|
|
}
|
|
|
|
func (provider *provider) BunDB() *bun.DB {
|
|
return provider.bundb.DB
|
|
}
|
|
|
|
func (provider *provider) SQLDB() *sql.DB {
|
|
return provider.sqldb
|
|
}
|
|
|
|
func (provider *provider) SQLxDB() *sqlx.DB {
|
|
return provider.sqlxdb
|
|
}
|
|
|
|
func (provider *provider) Dialect() sqlstore.SQLDialect {
|
|
return provider.dialect
|
|
}
|
|
|
|
func (provider *provider) BunDBCtx(ctx context.Context) bun.IDB {
|
|
return provider.bundb.BunDBCtx(ctx)
|
|
}
|
|
|
|
func (provider *provider) RunInTxCtx(ctx context.Context, opts *sql.TxOptions, cb func(ctx context.Context) error) error {
|
|
return provider.bundb.RunInTxCtx(ctx, opts, cb)
|
|
}
|