-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Updates/test updates
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//go:build !migrations | ||
|
||
package migrations | ||
|
||
import ( | ||
"gofr.dev/pkg/gofr/migration" | ||
) | ||
|
||
func createCollections() migration.Migrate { | ||
return migration.Migrate{ | ||
UP: func(d migration.Datasource) error { | ||
collections := []string{"tenants", "users", "api_keys"} | ||
for _, coll := range collections { | ||
if err := d.Mongo.CreateCollection(d.Context, coll); err != nil { | ||
Check failure on line 14 in cmd/api/migrations/20240226153000_create_collections.go
|
||
return err | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build !migrations | ||
|
||
package migrations | ||
|
||
import ( | ||
"gofr.dev/pkg/gofr/migration" | ||
) | ||
|
||
func createIndexes() migration.Migrate { | ||
return migration.Migrate{ | ||
UP: func(d migration.Datasource) error { | ||
// Create unique index on tenant name | ||
if err := d.Mongo.CreateIndex(d.Context, "tenants", map[string]interface{}{"name": 1}, true); err != nil { | ||
Check failure on line 13 in cmd/api/migrations/20240226153100_create_indexes.go
|
||
return err | ||
} | ||
|
||
// Create unique index on user email | ||
if err := d.Mongo.CreateIndex(d.Context, "users", map[string]interface{}{"email": 1}, true); err != nil { | ||
Check failure on line 18 in cmd/api/migrations/20240226153100_create_indexes.go
|
||
return err | ||
} | ||
|
||
// Create index on user's tenant_id for faster queries | ||
if err := d.Mongo.CreateIndex(d.Context, "users", map[string]interface{}{"tenant_id": 1}, false); err != nil { | ||
Check failure on line 23 in cmd/api/migrations/20240226153100_create_indexes.go
|
||
return err | ||
} | ||
|
||
// Create unique index on API key | ||
if err := d.Mongo.CreateIndex(d.Context, "api_keys", map[string]interface{}{"key": 1}, true); err != nil { | ||
Check failure on line 28 in cmd/api/migrations/20240226153100_create_indexes.go
|
||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !migrations | ||
|
||
package migrations | ||
|
||
import ( | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !migrations | ||
|
||
package migrations | ||
|
||
import ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !migrations | ||
|
||
package migrations | ||
|
||
import "gofr.dev/pkg/gofr/migration" | ||
|