fix(go): set max open connections to 1;

This commit is contained in:
VishalDalwadi
2026-04-08 16:19:18 +05:30
parent 0c91a37e6e
commit 32ca51db92
2 changed files with 25 additions and 6 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ func (s *sqliteConnector) connect() (*gorm.DB, error) {
return nil, err
}
//sqlDB.SetMaxOpenConns(1)
sqlDB.SetMaxOpenConns(1)
sqlDB.SetMaxIdleConns(1)
return db, nil
+24 -5
View File
@@ -93,7 +93,7 @@ func migrateV1_5_1(ctx context.Context) error {
}
func migrateUsers(ctx context.Context) error {
records, err := database.FetchRecords(database.USERS_TABLE_NAME)
records, err := FetchAll(ctx, database.USERS_TABLE_NAME)
if err != nil && !database.IsEmptyRecord(err) {
return err
}
@@ -147,7 +147,7 @@ func migrateUsers(ctx context.Context) error {
}
func migrateNetworks(ctx context.Context) error {
records, err := database.FetchRecords(database.NETWORKS_TABLE_NAME)
records, err := FetchAll(ctx, database.NETWORKS_TABLE_NAME)
if err != nil && !database.IsEmptyRecord(err) {
return err
}
@@ -286,7 +286,7 @@ func migrateNetworks(ctx context.Context) error {
}
func migrateUserRoles(ctx context.Context) error {
records, err := database.FetchRecords(database.USER_PERMISSIONS_TABLE_NAME)
records, err := FetchAll(ctx, database.USER_PERMISSIONS_TABLE_NAME)
if err != nil && !database.IsEmptyRecord(err) {
return err
}
@@ -311,7 +311,7 @@ func migrateUserRoles(ctx context.Context) error {
}
func migrateUserGroups(ctx context.Context) error {
records, err := database.FetchRecords(database.USER_GROUPS_TABLE_NAME)
records, err := FetchAll(ctx, database.USER_GROUPS_TABLE_NAME)
if err != nil && !database.IsEmptyRecord(err) {
return err
}
@@ -336,7 +336,7 @@ func migrateUserGroups(ctx context.Context) error {
}
func migrateHosts(ctx context.Context) error {
records, err := database.FetchRecords(database.HOSTS_TABLE_NAME)
records, err := FetchAll(ctx, database.HOSTS_TABLE_NAME)
if err != nil && !database.IsEmptyRecord(err) {
return err
}
@@ -423,3 +423,22 @@ func migrateHosts(ctx context.Context) error {
return nil
}
func FetchAll(ctx context.Context, tableName string) (map[string]string, error) {
row, err := db.FromContext(ctx).Raw("SELECT * FROM " + tableName + " ORDER BY key").Rows()
if err != nil {
return nil, err
}
records := make(map[string]string)
defer row.Close()
for row.Next() { // Iterate and fetch the records from result cursor
var key string
var value string
row.Scan(&key, &value)
records[key] = value
}
if len(records) == 0 {
return nil, gorm.ErrRecordNotFound
}
return records, nil
}