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

YDB Support #3

Merged
merged 25 commits into from
Jan 6, 2025
Merged

YDB Support #3

merged 25 commits into from
Jan 6, 2025

Conversation

art22m
Copy link

@art22m art22m commented Nov 9, 2024

No description provided.

|:--------------------:|:-----------------------------------------------------------:|
| `x-auth-token` | Authentication token. |
| `x-migrations-table` | Name of the migrations table (default `schema_migrations`). |
| `x-use-grpcs` | Enables gRPCS protocol for YDB connections (default grpc). |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required. Protocol defined in connection string directly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golang-migrate uses scheme to determine db driver --
https://github.com/golang-migrate/migrate/blob/master/database/driver.go#L86

}
}()

m, err := migrate.NewWithDatabaseInstance("file://./examples/migrations", "ydb", d)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a dot here?

Copy link
Author

@art22m art22m Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works without a dot here, but the tests for other dbs use the same approach, so I decided to leave it with dot for unification

return err
}

res, err := db.driver.Scripting().Execute(context.TODO(), string(rawMigrations), nil)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places you use db.driver.Query(), here we should also use it


createVersionTableQuery := fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
version Uint64,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add NOT NULL to scheme

}
defer func() { _ = d.Close(ctx) }()

res, err := d.Scripting().Execute(ctx, `
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db.driver.Query() here also

`, db.config.MigrationsTable)

insertVersionQuery := fmt.Sprintf(`
INSERT INTO %s (version, dirty, created) VALUES (%d, %t, CurrentUtcTimestamp())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a query with parameters here to eliminate compilation time from migration progress. I am not sure if it is meaningful, though, it is okay to do it with a Sprintf.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the difference would be in µs and this is a script which will be run manually, so I think Sprintf would be ok:)

ctx := context.TODO()

getVersionQuery := fmt.Sprintf(`
SELECT version, dirty FROM %s ORDER BY version DESC LIMIT 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You clear the table in SetVersion(), then maybe we do not need ORDER BY DESC LIMIT 1 here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ORDER BY DESC is not needed, and actually LIMIT 1 also not needed
but all other adapters use LIMIT 1, so I left this for unification

return err
}

dropQuery := fmt.Sprintf("DROP TABLE `%s`", table)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other db adapters in the repo use DROP TABLE IF EXISTS, I am not really sure why, but maybe we should keep it consistent and add IF EXISTS here

@asmyasnikov asmyasnikov merged commit 3835934 into ydb-platform:master Jan 6, 2025
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants