(t *testing.T)
| 351 | } |
| 352 | |
| 353 | func TestSanitizeQuery(t *testing.T) { |
| 354 | tests := []struct { |
| 355 | input string |
| 356 | want []string |
| 357 | wantErr bool |
| 358 | }{ |
| 359 | { |
| 360 | input: ` |
| 361 | --- 123456 |
| 362 | SELECT 1; |
| 363 | --- 6312 |
| 364 | SELECT 2; |
| 365 | ---123 |
| 366 | ---123 |
| 367 | /* 213123 */ |
| 368 | SELECT 3; |
| 369 | `, |
| 370 | want: []string{ |
| 371 | "SELECT 1", "SELECT 2", "SELECT 3", |
| 372 | }, |
| 373 | }, |
| 374 | { |
| 375 | input: ` |
| 376 | -- This is the bytebase schema to track migration info for Spanner |
| 377 | -- Create a database called bytebase in the driver. |
| 378 | -- CREATE DATABASE bytebase; |
| 379 | |
| 380 | -- Create migration_history table |
| 381 | CREATE TABLE migration_history ( |
| 382 | -- id is UUIDv4. |
| 383 | id STRING(MAX) NOT NULL, |
| 384 | created_by STRING(MAX) NOT NULL, |
| 385 | created_ts INT64 NOT NULL, |
| 386 | updated_by STRING(MAX) NOT NULL, |
| 387 | updated_ts INT64 NOT NULL, |
| 388 | -- Record the client version creating this migration history. For Bytebase, we use its binary release version. Different Bytebase release might |
| 389 | -- record different history info and this field helps to handle such situation properly. Moreover, it helps debugging. |
| 390 | release_version STRING(MAX) NOT NULL, |
| 391 | -- Allows granular tracking of migration history (e.g If an application manages schemas for a multi-tenant service and each tenant has its own schema, that application can use namespace to record the tenant name to track the per-tenant schema migration) |
| 392 | -- Since bytebase also manages different application databases from an instance, it leverages this field to track each database migration history. |
| 393 | namespace STRING(MAX) NOT NULL, |
| 394 | -- Used to detect out of order migration together with 'namespace' and 'version' column. |
| 395 | sequence INT64 NOT NULL, |
| 396 | CONSTRAINT sequence_is_non_negative CHECK (sequence >= 0), |
| 397 | -- Current allowed values are BASELINE, MIGRATE, MIGRATE_SDL, BRANCH, DATA. |
| 398 | type STRING(MAX) NOT NULL, |
| 399 | -- Current allowed values are PENDING, DONE, FAILED. |
| 400 | -- We create a "PENDING" record before applying the DDL and update that record to "DONE" after applying the DDL. |
| 401 | status STRING(MAX) NOT NULL, |
| 402 | -- Record the migration version. |
| 403 | version STRING(MAX) NOT NULL, |
| 404 | description STRING(MAX) NOT NULL, |
| 405 | -- Record the migration statement |
| 406 | statement STRING(MAX) NOT NULL, |
| 407 | -- Record the schema after migration |
| 408 | schema STRING(MAX) NOT NULL, |
| 409 | -- Record the schema before migration. Though we could also fetch it from the previous migration history, it would complicate fetching logic. |
| 410 | -- Besides, by storing the schema_prev, we can perform consistency check to see if the migration history has any gaps. |
nothing calls this directly
no test coverage detected