-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add ability to process vschema migrations during vttestserver startup #5054
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
Merged
tirsen
merged 1 commit into
vitessio:master
from
kalfonso:kalfonso.190801-vttestserver-alter-vschema
Aug 12, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
go/cmd/vttestserver/data/schema/app_customer/v001__create_customer_table.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| create table customers ( | ||
| id bigint, | ||
| name varchar(64), | ||
| age SMALLINT, | ||
| primary key (id) | ||
| ) Engine=InnoDB; | ||
|
|
1 change: 1 addition & 0 deletions
1
go/cmd/vttestserver/data/schema/app_customer/v002__add_customer_vschema.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| alter vschema on customers add vindex hash (id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "sharded": true, | ||
| "vindexes": { | ||
| "hash": { | ||
| "type": "hash" | ||
| } | ||
| }, | ||
| "tables": { | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
go/cmd/vttestserver/data/schema/test_keyspace/v001__create_test_table.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| create table test_table ( | ||
| id bigint, | ||
| name varchar(64), | ||
| age SMALLINT, | ||
| percent DECIMAL(5,2), | ||
| datetime_col DATETIME, | ||
| timestamp_col TIMESTAMP, | ||
| date_col DATE, | ||
| time_col TIME, | ||
| primary key (id) | ||
| ) Engine=InnoDB; | ||
|
|
1 change: 1 addition & 0 deletions
1
go/cmd/vttestserver/data/schema/test_keyspace/v002__create_hash_vindex.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| alter vschema create vindex my_vdx using hash |
1 change: 1 addition & 0 deletions
1
go/cmd/vttestserver/data/schema/test_keyspace/v003__add_table_vschema.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| alter vschema on test_table add vindex my_vdx (id) |
11 changes: 11 additions & 0 deletions
11
go/cmd/vttestserver/data/schema/test_keyspace/v004__create_test_table1.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| create table test_table1 ( | ||
| id bigint, | ||
| name varchar(64), | ||
| age SMALLINT, | ||
| percent DECIMAL(5,2), | ||
| datetime_col DATETIME, | ||
| timestamp_col TIMESTAMP, | ||
| date_col DATE, | ||
| time_col TIME, | ||
| primary key (id) | ||
| ) Engine=InnoDB; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "vitess.io/vitess/go/vt/vttest" | ||
|
|
||
| "github.com/golang/protobuf/jsonpb" | ||
| "vitess.io/vitess/go/vt/proto/logutil" | ||
| "vitess.io/vitess/go/vt/proto/vschema" | ||
| "vitess.io/vitess/go/vt/vtctl/vtctlclient" | ||
| ) | ||
|
|
||
| type columnVindex struct { | ||
| keyspace string | ||
| table string | ||
| vindex string | ||
| vindexType string | ||
| column string | ||
| } | ||
|
|
||
| func TestRunsVschemaMigrations(t *testing.T) { | ||
| schemaDirArg := "-schema_dir=data/schema" | ||
| webDirArg := "-web_dir=web/vtctld/app" | ||
| webDir2Arg := "-web_dir2=web/vtctld2/app" | ||
| tabletHostname := "-tablet_hostname=localhost" | ||
| keyspaceArg := "-keyspaces=test_keyspace,app_customer" | ||
| numShardsArg := "-num_shards=2,2" | ||
|
|
||
| os.Args = append(os.Args, []string{schemaDirArg, keyspaceArg, numShardsArg, webDirArg, webDir2Arg, tabletHostname}...) | ||
|
|
||
| cluster := runCluster() | ||
| defer cluster.TearDown() | ||
|
|
||
| assertColumnVindex(t, cluster, columnVindex{keyspace: "test_keyspace", table: "test_table", vindex: "my_vdx", vindexType: "hash", column: "id"}) | ||
| assertColumnVindex(t, cluster, columnVindex{keyspace: "app_customer", table: "customers", vindex: "hash", vindexType: "hash", column: "id"}) | ||
| } | ||
|
|
||
| func assertColumnVindex(t *testing.T, cluster vttest.LocalCluster, expected columnVindex) { | ||
| server := fmt.Sprintf("localhost:%v", cluster.GrpcPort()) | ||
| args := []string{"GetVSchema", expected.keyspace} | ||
| ctx := context.Background() | ||
|
|
||
| err := vtctlclient.RunCommandAndWait(ctx, server, args, func(e *logutil.Event) { | ||
| var keyspace vschema.Keyspace | ||
| if err := jsonpb.UnmarshalString(e.Value, &keyspace); err != nil { | ||
| t.Error(err) | ||
| } | ||
|
|
||
| columnVindex := keyspace.Tables[expected.table].ColumnVindexes[0] | ||
| actualVindex := keyspace.Vindexes[expected.vindex] | ||
| assertEqual(t, actualVindex.Type, expected.vindexType, "Actual vindex type different from expected") | ||
| assertEqual(t, columnVindex.Name, expected.vindex, "Actual vindex name different from expected") | ||
| assertEqual(t, columnVindex.Columns[0], expected.column, "Actual vindex column different from expected") | ||
| }) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| } | ||
|
|
||
| func assertEqual(t *testing.T, actual string, expected string, message string) { | ||
| if actual != expected { | ||
| t.Errorf("%s: actual %s, expected %s", message, actual, expected) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.