Files
ent/dialect/sql/schema/atlas_test.go
Jannik Clausen 7017cbc898 dialect/sql/schema: file based type store (#2644)
* dialect/sql/schema: file based type store

This PR adds support for a file based type storage when using versioned migrations. The file called `.ent_types` is written to the migration directory alongside the migration files and will be kept in sync for every migration file generation run.

In order to not break existing code, where the type storage might differ for different deployment, global unique ID mut be enabled by using a new option. This will also be raised as an error to the user when attempting to use versioned migrations and global unique ID.

Documentation will be added to this PR once feedback on the code is gathered.

* apply CR

* fix tests

* change format of types file to exclude it from atlas.sum file

* docs and drift test

* apply CR
2022-06-15 16:10:15 +02:00

34 lines
815 B
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package schema
import (
"context"
"os"
"path/filepath"
"testing"
"ariga.io/atlas/sql/migrate"
"github.com/stretchr/testify/require"
)
func TestDirTypeStore(t *testing.T) {
ex := []string{"a", "b", "c"}
p := t.TempDir()
d, err := migrate.NewLocalDir(p)
require.NoError(t, err)
s := &dirTypeStore{d}
require.NoError(t, s.save(ex))
require.FileExists(t, filepath.Join(p, entTypes))
c, err := os.ReadFile(filepath.Join(p, entTypes))
require.NoError(t, err)
require.Contains(t, string(c), atlasDirective)
ac, err := s.load(context.Background(), nil)
require.NoError(t, err)
require.Equal(t, ex, ac)
}