Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support database indexes #59

Open
ImpressionableRaccoon opened this issue Jun 27, 2023 · 0 comments
Open

feat: support database indexes #59

ImpressionableRaccoon opened this issue Jun 27, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@ImpressionableRaccoon
Copy link
Contributor

https://gorm.io/docs/indexes.html
https://ydb.tech/en/docs/yql/reference/syntax/alter_table#secondary-index

behavior now:
db.AutoMigrate() failed when index already created

func TestSequentialAutoMigrateWithIndex(t *testing.T) {
	type Migrations struct {
		ID      string `gorm:"primarykey;not null"`
		Payload string `gorm:"index"`
	}

	dsn, has := os.LookupEnv("YDB_CONNECTION_STRING")
	if !has {
		t.Skip("skip test '" + t.Name() + "' without env 'YDB_CONNECTION_STRING'")
	}

	pathPrefix := t.Name()

	for i := 0; i < 5; i++ {
		t.Run("", func(t *testing.T) {
			db, err := gorm.Open(
				ydb.Open(dsn,
					ydb.WithTablePathPrefix(pathPrefix),
				),
			)
			require.NoError(t, err)
			require.NotNil(t, db)

			db = db.Debug()

			err = db.AutoMigrate(&Migrations{})
			require.NoError(t, err)
		})
	}
}

result:

=== RUN   TestSequentialAutoMigrateWithIndex/#00

[494.824ms] [rows:0] CREATE TABLE `migrations` (`id` Utf8 NOT NULL,`payload` Utf8,PRIMARY KEY (`id`),INDEX `idx_migrations_payload` GLOBAL ON (`payload`))

    --- PASS: TestSequentialAutoMigrateWithIndex/#00 (3.18s)


=== RUN   TestSequentialAutoMigrateWithIndex/#01

[959.834ms] [rows:-] SELECT DATABASE()

[1095.721ms] [rows:-] SELECT count(*) FROM information_schema.statistics WHERE table_schema = $1 AND table_name = $2 AND index_name = $3

[327.297ms] [rows:0] CREATE INDEX `idx_migrations_payload` ON `migrations`(`payload`)

operation/GENERIC_ERROR (code = 400080, address = ..., issues = [{4:0 => 'Unexpected token 'CREATE' : cannot match to any predicted input...'}])
at `github.com/ydb-platform/ydb-go-sdk/v3/internal/conn.(*conn).Invoke(conn.go:361)`
at `github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer.(*Balancer).wrapCall(balancer.go:293)`
at `github.com/ydb-platform/ydb-go-sdk/v3/internal/table.(*session).executeDataQuery(session.go:733)`
at `github.com/ydb-platform/ydb-go-sdk/v3/internal/table.(*session).Execute(session.go:688)`
at `github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.(*conn).execContext(conn.go:190)`

    --- FAIL: TestSequentialAutoMigrateWithIndex/#01 (5.83s)
@ImpressionableRaccoon ImpressionableRaccoon added the enhancement New feature or request label Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant