diff --git a/config.go b/config.go index 283ca56..e33a0ad 100644 --- a/config.go +++ b/config.go @@ -7,13 +7,8 @@ type Config struct { limitNormalizeNode int } -func NewDefaultConfig() Config { - return Config{limitNormalizeNode: 10000} -} - -func (cc Config) WithDataDir(dir string) Config { - cc.dataDir = dir - return cc +func NewDefaultConfig(dir string) Config { + return Config{dataDir: dir, limitNormalizeNode: 10000} } func (cc Config) WithLimitNormalizeNode(n int) Config { diff --git a/db.go b/db.go index de4a474..d219bbe 100644 --- a/db.go +++ b/db.go @@ -142,7 +142,7 @@ func (db *DB) DropData(ctx context.Context) error { return nil } -func (db *DB) AlterSchema(ctx context.Context, sch string) error { +func (db *DB) AlterSchema(ctx context.Context, sch string, ns uint64) error { db.mutex.Lock() defer db.mutex.Unlock() @@ -150,7 +150,7 @@ func (db *DB) AlterSchema(ctx context.Context, sch string) error { return ErrDBClosed } - sc, err := schema.ParseWithNamespace(sch, 0) + sc, err := schema.ParseWithNamespace(sch, ns) if err != nil { return fmt.Errorf("error parsing schema: %w", err) } diff --git a/db_test.go b/db_test.go index a49bf3a..a86bb4d 100644 --- a/db_test.go +++ b/db_test.go @@ -16,12 +16,12 @@ import ( func TestRestart(t *testing.T) { dataDir := t.TempDir() - db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(dataDir)) + db, err := modusdb.New(modusdb.NewDefaultConfig(dataDir)) require.NoError(t, err) defer func() { db.Close() }() require.NoError(t, db.DropAll(context.Background())) - require.NoError(t, db.AlterSchema(context.Background(), "name: string @index(term) .")) + require.NoError(t, db.AlterSchema(context.Background(), "name: string @index(term) .", 0)) _, err = db.Mutate(context.Background(), []*api.Mutation{ { @@ -47,7 +47,7 @@ func TestRestart(t *testing.T) { require.JSONEq(t, `{"me":[{"name":"A"}]}`, string(qresp.GetJson())) db.Close() - db, err = modusdb.New(modusdb.NewDefaultConfig().WithDataDir(dataDir)) + db, err = modusdb.New(modusdb.NewDefaultConfig(dataDir)) require.NoError(t, err) qresp, err = db.Query(context.Background(), query) require.NoError(t, err) @@ -57,7 +57,7 @@ func TestRestart(t *testing.T) { } func TestSchemaQuery(t *testing.T) { - db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir())) + db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir())) require.NoError(t, err) defer db.Close() @@ -68,7 +68,7 @@ func TestSchemaQuery(t *testing.T) { married: bool . loc: geo . dob: datetime . - `)) + `, 0)) resp, err := db.Query(context.Background(), `schema(pred: [name, age]) {type}`) require.NoError(t, err) @@ -86,13 +86,13 @@ func TestBasicVector(t *testing.T) { } vectBytes := buf.Bytes() - db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir())) + db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir())) require.NoError(t, err) defer db.Close() require.NoError(t, db.DropAll(context.Background())) require.NoError(t, db.AlterSchema(context.Background(), - `project_description_v: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .`)) + `project_description_v: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .`, 0)) uids, err := db.Mutate(context.Background(), []*api.Mutation{{ Set: []*api.NQuad{{ diff --git a/live.go b/live.go index a8a83db..a369f08 100644 --- a/live.go +++ b/live.go @@ -36,7 +36,7 @@ func (db *DB) Load(ctx context.Context, schemaPath, dataPath string) error { if err != nil { return fmt.Errorf("error reading schema file [%v]: %w", schemaPath, err) } - if err := db.AlterSchema(ctx, string(schemaData)); err != nil { + if err := db.AlterSchema(ctx, string(schemaData), 0); err != nil { return fmt.Errorf("error altering schema: %w", err) } diff --git a/live_test.go b/live_test.go index 7fb1b73..825f4b4 100644 --- a/live_test.go +++ b/live_test.go @@ -42,7 +42,7 @@ func TestLiveLoaderSmall(t *testing.T) { ` ) - db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir())) + db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir())) require.NoError(t, err) defer func() { db.Close() }() @@ -83,7 +83,7 @@ func TestLiveLoaderSmall(t *testing.T) { } func TestLiveLoader1Million(t *testing.T) { - db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir())) + db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir())) require.NoError(t, err) defer func() { db.Close() }() diff --git a/vector_test.go b/vector_test.go index 60c7f50..f27e1b6 100644 --- a/vector_test.go +++ b/vector_test.go @@ -20,13 +20,13 @@ const ( ) func TestVectorDelete(t *testing.T) { - db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir())) + db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir())) require.NoError(t, err) defer func() { db.Close() }() require.NoError(t, db.DropAll(context.Background())) require.NoError(t, db.AlterSchema(context.Background(), - fmt.Sprintf(vectorSchemaWithIndex, "vtest", "4", "euclidean"))) + fmt.Sprintf(vectorSchemaWithIndex, "vtest", "4", "euclidean"), 0)) // insert random vectorss assignIDs, err := db.LeaseUIDs(numVectors + 1)