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

Support check constraint frontend v2 #19

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
75deab6
Check constraint backend (#9)
taherkl Nov 27, 2024
472b979
Merge remote-tracking branch 'upstream/master'
Nov 27, 2024
40e9798
sync master
Nov 27, 2024
60e6635
update api
Nov 27, 2024
d3ef5b9
fix PR comment
Nov 28, 2024
85bc610
Merge branch 'GoogleCloudPlatform:master' into support-check-constrai…
akashthawaitcc Dec 3, 2024
8eb044c
remove api call to while validating constraints
akashthawaitcc Dec 5, 2024
954c368
Fixed db collation regex to remove collation name from the results
akashthawaitcc Dec 5, 2024
fc4c19f
renamed function name to formatCheckConstraints and added check if co…
akashthawaitcc Dec 5, 2024
1d2e5e3
fixed PR comments
akashthawaitcc Dec 5, 2024
449e6f8
added test case for the empty check constraint name
akashthawaitcc Dec 5, 2024
b81e3b2
fix: added regular exprression to match the exact column
akashthawaitcc Dec 5, 2024
33eb995
fix: added regular expression to replace table name
akashthawaitcc Dec 5, 2024
bdca561
Merge remote-tracking branch 'upstream/master'
Dec 9, 2024
c37bae9
Merge pull request #11 from GoogleCloudPlatform/master
taherkl Dec 9, 2024
5d4c52e
Merge branch 'master' into support-check-constraint-backend
akashthawaitcc Dec 10, 2024
41424a2
Added test case for the column rename for check constraint
akashthawaitcc Dec 12, 2024
3f9b616
1. Refactored GetConstraint function
akashthawaitcc Dec 12, 2024
df31d35
added comment at handling case for check constraints
akashthawaitcc Dec 12, 2024
491e5db
reverted white spaces
akashthawaitcc Dec 12, 2024
e64bd55
reverted white spaces
akashthawaitcc Dec 12, 2024
67c71c2
nit: doesCheckConstraintNameExist
akashthawaitcc Dec 12, 2024
6564582
added comments for doesCheckConstraintNameExist
Dec 13, 2024
ea92a24
PR and UT fixes
Dec 13, 2024
5f20127
Merge branch 'master' into support-check-constraint-backend
Dec 13, 2024
eb1e4b0
fix UT
Dec 13, 2024
31b2ac1
UT fix
Dec 13, 2024
283e358
Removed isCheckConstraintsTablePresent function
Dec 13, 2024
79332a4
moved regex globally
Dec 13, 2024
430bebc
Fix UT
Dec 13, 2024
df77473
fixed UT
akashthawaitcc Dec 13, 2024
6fb655d
fixed handling of the constraints
Dec 13, 2024
86bbab7
removed unused function
akashthawaitcc Dec 16, 2024
69d91ca
added unit tests for incompatable name
akashthawaitcc Dec 16, 2024
91c2b9a
Combined unit tests
akashthawaitcc Dec 16, 2024
a0ec7eb
added test case for the renaming column having substring of other column
akashthawaitcc Dec 16, 2024
0954a27
added the query changes which return distinct value
Dec 17, 2024
0428c80
Merge branch 'master' into support-check-constraint-backend
taherkl Dec 17, 2024
780b0fb
Updating version of msprod (#969)
VardhanThigle Dec 20, 2024
81d7631
fix(deps): update module golang.org/x/net to v0.33.0 [security] (#967)
renovate-bot Dec 20, 2024
1b5cf7d
feat: APIs for Backend Changes for Default Values (#965)
asthamohta Dec 20, 2024
e1f6d28
feat: default value for mysql source (#963)
asthamohta Dec 20, 2024
ed259de
Updating version of msprod (#969)
VardhanThigle Dec 20, 2024
10391eb
fix(deps): update module golang.org/x/net to v0.33.0 [security] (#967)
renovate-bot Dec 20, 2024
971a2de
feat: APIs for Backend Changes for Default Values (#965)
asthamohta Dec 20, 2024
88127a3
feat: default value for mysql source (#963)
asthamohta Dec 20, 2024
b095eee
Check constraint backend (#9)
taherkl Nov 27, 2024
d8c562d
1. Refactored GetConstraint function
akashthawaitcc Dec 12, 2024
a78d24a
sync master
Dec 20, 2024
734593f
chore(deps): update dependency jasmine-core to ~5.5.0 (#953)
renovate-bot Dec 20, 2024
3020bfd
removed duplicate function
Dec 20, 2024
0fb39e4
Merge branch 'master' into support-check-constraint-backend
taherkl Dec 20, 2024
deabaa6
Fixed UT
Dec 20, 2024
4606e74
Merge pull request #20 from GoogleCloudPlatform/master
taherkl Dec 20, 2024
7709c06
feat: make spanner config mandatory for schema migration (#970)
asthamohta Dec 20, 2024
0275834
chore(deps): update gcr.io/cloud-spanner-emulator/emulator docker tag…
renovate-bot Dec 23, 2024
fd0dc21
chore(deps): update dependency @types/node to v20.17.10 (#973)
renovate-bot Dec 23, 2024
cb27339
Merge branch 'GoogleCloudPlatform:master' into master
akashthawaitcc Dec 23, 2024
b142a67
Merge branch 'master' into support-check-constraint-backend
akashthawaitcc Dec 26, 2024
1a4e61b
Add Support for Check Constraint - Backend code changes (#945)
taherkl Dec 26, 2024
930fd6c
Check constraint backend (#9)
taherkl Nov 27, 2024
6fc11b6
removed duplicate code after rebase
akashthawaitcc Dec 26, 2024
731346f
Merge branch 'GoogleCloudPlatform:master' into master
akashthawaitcc Dec 26, 2024
74239c2
Check constraint backend (#9)
taherkl Nov 27, 2024
383d3dc
update api
Nov 27, 2024
9aa4573
fix PR comment
Nov 28, 2024
8dd1742
remove api call to while validating constraints
akashthawaitcc Dec 5, 2024
6b03099
Fixed db collation regex to remove collation name from the results
akashthawaitcc Dec 5, 2024
3e157f3
renamed function name to formatCheckConstraints and added check if co…
akashthawaitcc Dec 5, 2024
63e2a59
fixed PR comments
akashthawaitcc Dec 5, 2024
a973c5d
added test case for the empty check constraint name
akashthawaitcc Dec 5, 2024
51e7051
fix: added regular exprression to match the exact column
akashthawaitcc Dec 5, 2024
3c5a203
fix: added regular expression to replace table name
akashthawaitcc Dec 5, 2024
099b404
Added test case for the column rename for check constraint
akashthawaitcc Dec 12, 2024
85f2869
1. Refactored GetConstraint function
akashthawaitcc Dec 12, 2024
54ab841
added comment at handling case for check constraints
akashthawaitcc Dec 12, 2024
e0edb33
reverted white spaces
akashthawaitcc Dec 12, 2024
3b173d0
reverted white spaces
akashthawaitcc Dec 12, 2024
651f174
nit: doesCheckConstraintNameExist
akashthawaitcc Dec 12, 2024
1f85c5a
added comments for doesCheckConstraintNameExist
Dec 13, 2024
7a3b49e
PR and UT fixes
Dec 13, 2024
4db55b0
fix UT
Dec 13, 2024
e090647
UT fix
Dec 13, 2024
d6b621b
Removed isCheckConstraintsTablePresent function
Dec 13, 2024
7410210
moved regex globally
Dec 13, 2024
b98a93d
Fix UT
Dec 13, 2024
863c8f9
fixed UT
akashthawaitcc Dec 13, 2024
b64f8c7
fixed handling of the constraints
Dec 13, 2024
cb7b394
removed unused function
akashthawaitcc Dec 16, 2024
885b3c4
added unit tests for incompatable name
akashthawaitcc Dec 16, 2024
81f3690
Combined unit tests
akashthawaitcc Dec 16, 2024
a70db08
added test case for the renaming column having substring of other column
akashthawaitcc Dec 16, 2024
1937320
added the query changes which return distinct value
Dec 17, 2024
d3e9188
feat: APIs for Backend Changes for Default Values (#965)
asthamohta Dec 20, 2024
82652c8
feat: default value for mysql source (#963)
asthamohta Dec 20, 2024
5aceba3
Check constraint backend (#9)
taherkl Nov 27, 2024
c21cc9a
1. Refactored GetConstraint function
akashthawaitcc Dec 12, 2024
634c035
removed duplicate function
Dec 20, 2024
c1720e6
Fixed UT
Dec 20, 2024
0534df3
Check constraint backend (#9)
taherkl Nov 27, 2024
96068b2
removed duplicate code after rebase
akashthawaitcc Dec 26, 2024
149e780
Merge branch 'support-check-constraint-backend' of github.com:olliono…
akashthawaitcc Dec 26, 2024
0c41388
removed duplicate constants
akashthawaitcc Dec 26, 2024
f220876
Merge branch 'master' into support-check-constraint-backend
akashthawaitcc Dec 26, 2024
ef3c414
Merge pull request #21 from ollionorg/support-check-constraint-backend
akashthawaitcc Dec 26, 2024
243107e
Support check constraint backend (#962)
taherkl Dec 18, 2024
d3baed5
Feat/fe check contraints (#10)
taherkl Dec 2, 2024
0cd88e1
updated the regrex for constraint name
VivekY1098 Dec 10, 2024
fc6dbdd
address the comment
Dec 12, 2024
d176ffd
addressed the comment
Dec 12, 2024
f06d7af
address the comment
Dec 13, 2024
53e8205
address the comment
VivekY1098 Dec 13, 2024
a7c2b72
fixed regular expression for check constraints name
akashthawaitcc Dec 16, 2024
fb6e7a8
remove the node-sql-parser package
Dec 17, 2024
fb9f65d
handle check constraint without name.
Dec 17, 2024
250aef4
resolve the duplicate issue
VivekY1098 Dec 17, 2024
afe02d7
Check constraint backend (#9)
taherkl Nov 27, 2024
26e44b9
renamed function name to formatCheckConstraints and added check if co…
akashthawaitcc Dec 5, 2024
c92bde8
fixed PR comments
akashthawaitcc Dec 5, 2024
724558d
fix: added regular exprression to match the exact column
akashthawaitcc Dec 5, 2024
5587646
Added test case for the column rename for check constraint
akashthawaitcc Dec 12, 2024
5d55b73
PR and UT fixes
Dec 13, 2024
9751a39
added the verification api integration and struct changes
Dec 14, 2024
402c7aa
added the verification at connect button
Dec 17, 2024
e24e951
added the integration of expression api
Dec 17, 2024
74c5517
code fix for expression api implementation
Dec 18, 2024
fa350b2
code fix for expression verification on initial call
Dec 18, 2024
8646a01
added partial unit test of verify check constraint expression
akashthawaitcc Dec 18, 2024
66aebbe
refactored expression verfication api mock
akashthawaitcc Dec 18, 2024
bbee059
Test added for verification api
Dec 18, 2024
5aa9550
fix the UT issue
Dec 18, 2024
8aeb400
Support check constraint backend (#962)
taherkl Dec 18, 2024
550a4ad
Fixed unit test and code refactor
akashthawaitcc Dec 18, 2024
e59d96c
fixed unit tests
akashthawaitcc Dec 18, 2024
9119d69
added source in conv object
Dec 18, 2024
44acd61
front-end ut fixed
Dec 19, 2024
017ed0a
removed node sql parser import
akashthawaitcc Dec 19, 2024
7e77c81
removed node dependencies
akashthawaitcc Dec 19, 2024
d7f0e90
rename handler
akashthawaitcc Dec 19, 2024
0b8be85
added the generation of constraint name
Dec 19, 2024
c87673d
added dump flow
akashthawaitcc Dec 20, 2024
a5fc9bb
added dump flow
Dec 20, 2024
20d2da9
Feat/fe check contraints (#10)
taherkl Dec 2, 2024
1ad9c50
address the comment
Dec 12, 2024
3ee835b
remove the node-sql-parser package
Dec 17, 2024
5a2562c
Check constraint backend (#9)
taherkl Nov 27, 2024
984c4a2
fixed PR comments
akashthawaitcc Dec 5, 2024
6c4deaa
fix: added regular exprression to match the exact column
akashthawaitcc Dec 5, 2024
d2ad42f
Added test case for the column rename for check constraint
akashthawaitcc Dec 12, 2024
18244ec
nit: doesCheckConstraintNameExist
akashthawaitcc Dec 12, 2024
1b3c3ea
moved regex globally
Dec 13, 2024
009d853
modify the query to fetch the check constraint
Dec 13, 2024
c915ab7
added the verification api integration and struct changes
Dec 14, 2024
6453423
added partial unit test of verify check constraint expression
akashthawaitcc Dec 18, 2024
59aed29
refactored expression verfication api mock
akashthawaitcc Dec 18, 2024
a4546cc
Test added for verification api
Dec 18, 2024
b2c193d
Support check constraint backend (#962)
taherkl Dec 18, 2024
0c69ef6
Fixed unit test and code refactor
akashthawaitcc Dec 18, 2024
2cfbfc8
removed node dependencies
akashthawaitcc Dec 19, 2024
cd14ba2
added dump flow
Dec 20, 2024
53282a7
Feat/fe check contraints (#10)
taherkl Dec 2, 2024
2639829
address the comment
Dec 12, 2024
0680ef1
remove the node-sql-parser package
Dec 17, 2024
8d39e72
Check constraint backend (#9)
taherkl Nov 27, 2024
50f6324
added the verification api integration and struct changes
Dec 14, 2024
e5cc82e
added partial unit test of verify check constraint expression
akashthawaitcc Dec 18, 2024
138c659
refactored expression verfication api mock
akashthawaitcc Dec 18, 2024
eb4b55c
Test added for verification api
Dec 18, 2024
db1789d
Support check constraint backend (#962)
taherkl Dec 18, 2024
d9cef66
removed node dependencies
akashthawaitcc Dec 19, 2024
05b25b2
Feat/fe check contraints (#10)
taherkl Dec 2, 2024
75dbd00
address the comment
Dec 12, 2024
224691f
remove the node-sql-parser package
Dec 17, 2024
62dfea0
Check constraint backend (#9)
taherkl Nov 27, 2024
8c91058
added the verification api integration and struct changes
Dec 14, 2024
7bbf485
added partial unit test of verify check constraint expression
akashthawaitcc Dec 18, 2024
0c2f617
refactored expression verfication api mock
akashthawaitcc Dec 18, 2024
a5a7304
Test added for verification api
Dec 18, 2024
8fcf964
Support check constraint backend (#962)
taherkl Dec 18, 2024
0105deb
removed node dependencies
akashthawaitcc Dec 19, 2024
e3f5d2d
added UT
Dec 23, 2024
feb6589
address the comment
Dec 24, 2024
05d3860
updated the table exist query for version8.0.16
Dec 26, 2024
a159b7e
Feat/fe check contraints (#10)
taherkl Dec 2, 2024
640d19e
address the comment
Dec 12, 2024
39c9de9
address the comment
Dec 13, 2024
f2300f8
rebase commit
akashthawaitcc Dec 26, 2024
ef5be67
fixed regular expression for check constraints name
akashthawaitcc Dec 16, 2024
5940dbf
remove the node-sql-parser package
Dec 17, 2024
5e57810
resolve the duplicate issue
VivekY1098 Dec 17, 2024
9788c6b
renamed function name to formatCheckConstraints and added check if co…
akashthawaitcc Dec 5, 2024
5c5a3e7
fix: added regular exprression to match the exact column
akashthawaitcc Dec 5, 2024
fa43691
Added test case for the column rename for check constraint
akashthawaitcc Dec 12, 2024
245b803
reverted white spaces
akashthawaitcc Dec 12, 2024
732d4cf
reverted white spaces
akashthawaitcc Dec 12, 2024
b30991a
added the verification api integration and struct changes
Dec 14, 2024
73c261b
added the integration of expression api
Dec 17, 2024
d82df82
code fix for expression api implementation
Dec 18, 2024
e38fca2
code fix for expression verification on initial call
Dec 18, 2024
59642e2
added partial unit test of verify check constraint expression
akashthawaitcc Dec 18, 2024
f6805f9
refactored expression verfication api mock
akashthawaitcc Dec 18, 2024
153ed3b
Test added for verification api
Dec 18, 2024
486215a
Support check constraint backend (#962)
taherkl Dec 18, 2024
32e7b23
fixed unit tests
akashthawaitcc Dec 18, 2024
5ac78e5
front-end ut fixed
Dec 19, 2024
a636517
removed node sql parser import
akashthawaitcc Dec 19, 2024
9d3a58a
removed node dependencies
akashthawaitcc Dec 19, 2024
94b3f1b
rename handler
akashthawaitcc Dec 19, 2024
55b7595
added the generation of constraint name
Dec 19, 2024
41e6e7e
added dump flow
Dec 20, 2024
c924e16
Feat/fe check contraints (#10)
taherkl Dec 2, 2024
fe33c30
address the comment
Dec 12, 2024
c7f867d
remove the node-sql-parser package
Dec 17, 2024
99d4dbf
Check constraint backend (#9)
taherkl Nov 27, 2024
883bcdd
Support check constraint backend (#962)
taherkl Dec 18, 2024
4c40958
Feat/fe check contraints (#10)
taherkl Dec 2, 2024
aff4c81
Check constraint backend (#9)
taherkl Nov 27, 2024
1157b86
Support check constraint backend (#962)
taherkl Dec 18, 2024
bb05787
PR comment fixes and feedback changes(#23)
VivekY1098 Dec 30, 2024
3722d96
resolve conflict error
Dec 30, 2024
ba6f41e
fix npm ci
Dec 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .github/workflows/integration-tests-against-emulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

services:
spanner_emulator:
image: gcr.io/cloud-spanner-emulator/emulator:1.5.27
image: gcr.io/cloud-spanner-emulator/emulator:1.5.28
ports:
- 9010:9010
- 9020:9020
Expand Down Expand Up @@ -114,21 +114,28 @@ jobs:
- run: mysql -v -P 3306 --protocol=tcp -u root -proot < test_data/mysql_foreignkeyaction_dump.test.out

# init sql server with test_data
# since we use ubuntu-latest container, we should ensure that the path matches the latest from https://packages.microsoft.com/config/ubuntu/
# while its possible to infer the latest from the path in the run script, it will make the run section more complex and hard to maintian.
- name: Install sqlcmd required for loading .sql files
run: |
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
- run: sqlcmd -?
- run: sqlcmd -U sa -P ${MSSQL_SA_PASSWORD} -i test_data/sqlserver.test.out
curl https://packages.microsoft.com/config/ubuntu/24.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
sudo apt-get install mssql-tools18 unixodbc-dev
set -x
ls /opt/mssql-tools18/bin/
set +x
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
- run: /opt/mssql-tools18/bin/sqlcmd -C -?
- run: /opt/mssql-tools18/bin/sqlcmd -U sa -P ${MSSQL_SA_PASSWORD} -i test_data/sqlserver.test.out -C

# sqlplus set up init oracle db.
- name: Install sqlplus required for loading .sql files
run: |
sudo apt-get update
sudo apt-get install -y libaio1 rpm2cpio cpio
sudo apt-get install -y libaio1t64 rpm2cpio cpio
sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/libaio.so.1
curl -O https://download.oracle.com/otn_software/linux/instantclient/2340000/oracle-instantclient-basic-23.4.0.24.05-1.el9.x86_64.rpm
curl -O https://download.oracle.com/otn_software/linux/instantclient/2340000/oracle-instantclient-sqlplus-23.4.0.24.05-1.el9.x86_64.rpm
rpm2cpio oracle-instantclient-basic-23.4.0.24.05-1.el9.x86_64.rpm | sudo cpio -idmv
Expand Down
26 changes: 15 additions & 11 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@ const (
AddIndex = "add_index"
EditColumnMaxLength = "edit_column_max_length"
AddShardIdPrimaryKey = "add_shard_id_primary_key"
//bulk migration type
// bulk migration type
BULK_MIGRATION = "bulk"
//dataflow migration type
// dataflow migration type
DATAFLOW_MIGRATION = "dataflow"
//DMS migration type
// DMS migration type
DMS_MIGRATION = "dms"

SESSION_FILE = "sessionFile"

//Default shardId
// Default shardId
DEFAULT_SHARD_ID string = "smt-default"
//Metadata database name
// Metadata database name
METADATA_DB string = "spannermigrationtool_metadata"
//Migration types
// Migration types
MINIMAL_DOWNTIME_MIGRATION = "minimal_downtime"
//Job Resource Types
// Job Resource Types
DATAFLOW_RESOURCE string = "dataflow"
PUBSUB_RESOURCE string = "pubsub"
DLQ_PUBSUB_RESOURCE string = "dlq_pubsub"
Expand All @@ -111,7 +111,7 @@ const (
// Default gcs path of the Dataflow template.
DEFAULT_TEMPLATE_PATH string = "gs://dataflow-templates/latest/flex/Cloud_Datastream_to_Spanner"

//FK Actions
// FK Actions
FK_NO_ACTION string = "NO ACTION"
FK_CASCADE string = "CASCADE"
FK_SET_DEFAULT string = "SET DEFAULT"
Expand All @@ -122,8 +122,12 @@ const (
REGULAR_GCS string = "data"
DLQ_GCS string = "dlq"

//VerifyExpresions API
CHECK_EXPRESSION = "CHECK"
// VerifyExpresions API
CHECK_EXPRESSION = "CHECK"
DEFAUT_EXPRESSION = "DEFAULT"

DEFAULT_GENERATED = "DEFAULT_GENERATED"
TEMP_DB = "smt-staging-db"

// Regex for matching database collation
DB_COLLATION_REGEX = `(_[a-zA-Z0-9]+\\|\\)`
)
4 changes: 3 additions & 1 deletion common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"cloud.google.com/go/storage"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/constants"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/parse"
"github.com/GoogleCloudPlatform/spanner-migration-tool/expressions_api"
"github.com/GoogleCloudPlatform/spanner-migration-tool/internal"
"github.com/GoogleCloudPlatform/spanner-migration-tool/sources/common"
"github.com/GoogleCloudPlatform/spanner-migration-tool/sources/spanner"
Expand Down Expand Up @@ -445,7 +446,8 @@ func GetLegacyModeSupportedDrivers() []string {
func ReadSpannerSchema(ctx context.Context, conv *internal.Conv, client *sp.Client) error {
infoSchema := spanner.InfoSchemaImpl{Client: client, Ctx: ctx, SpDialect: conv.SpDialect}
processSchema := common.ProcessSchemaImpl{}
err := processSchema.ProcessSchema(conv, infoSchema, common.DefaultWorkers, internal.AdditionalSchemaAttributes{IsSharded: false}, &common.SchemaToSpannerImpl{}, &common.UtilsOrderImpl{}, &common.InfoSchemaImpl{})
expressionVerificationAccessor, _ := expressions_api.NewExpressionVerificationAccessorImpl(ctx, conv.SpProjectId, conv.SpInstanceId)
err := processSchema.ProcessSchema(conv, infoSchema, common.DefaultWorkers, internal.AdditionalSchemaAttributes{IsSharded: false}, &common.SchemaToSpannerImpl{ExpressionVerificationAccessor: expressionVerificationAccessor}, &common.UtilsOrderImpl{}, &common.InfoSchemaImpl{})
if err != nil {
return fmt.Errorf("error trying to read and convert spanner schema: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/constants"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/task"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/utils"
"github.com/GoogleCloudPlatform/spanner-migration-tool/expressions_api"
"github.com/GoogleCloudPlatform/spanner-migration-tool/internal"
"github.com/GoogleCloudPlatform/spanner-migration-tool/internal/reports"
"github.com/GoogleCloudPlatform/spanner-migration-tool/profiles"
Expand Down Expand Up @@ -79,7 +80,8 @@ func (ci *ConvImpl) SchemaConv(migrationProjectId string, sourceProfile profiles
case constants.POSTGRES, constants.MYSQL, constants.DYNAMODB, constants.SQLSERVER, constants.ORACLE:
return schemaFromSource.schemaFromDatabase(migrationProjectId, sourceProfile, targetProfile, &GetInfoImpl{}, &common.ProcessSchemaImpl{})
case constants.PGDUMP, constants.MYSQLDUMP:
return schemaFromSource.SchemaFromDump(sourceProfile.Driver, targetProfile.Conn.Sp.Dialect, ioHelper, &ProcessDumpByDialectImpl{})
expressionVerificationAccessor, _ := expressions_api.NewExpressionVerificationAccessorImpl(context.Background(), targetProfile.Conn.Sp.Project, targetProfile.Conn.Sp.Instance)
return schemaFromSource.SchemaFromDump(sourceProfile.Driver, targetProfile.Conn.Sp.Dialect, ioHelper, &ProcessDumpByDialectImpl{expressionVerificationAccessor})
default:
return nil, fmt.Errorf("schema conversion for driver %s not supported", sourceProfile.Driver)
}
Expand Down
14 changes: 13 additions & 1 deletion conversion/conversion_from_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/constants"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/metrics"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/utils"
"github.com/GoogleCloudPlatform/spanner-migration-tool/expressions_api"
"github.com/GoogleCloudPlatform/spanner-migration-tool/internal"
"github.com/GoogleCloudPlatform/spanner-migration-tool/logger"
"github.com/GoogleCloudPlatform/spanner-migration-tool/profiles"
Expand Down Expand Up @@ -54,6 +55,9 @@ type DataFromSourceImpl struct{}
func (sads *SchemaFromSourceImpl) schemaFromDatabase(migrationProjectId string, sourceProfile profiles.SourceProfile, targetProfile profiles.TargetProfile, getInfo GetInfoInterface, processSchema common.ProcessSchemaInterface) (*internal.Conv, error) {
conv := internal.MakeConv()
conv.SpDialect = targetProfile.Conn.Sp.Dialect
conv.SpProjectId = targetProfile.Conn.Sp.Project
conv.SpInstanceId = targetProfile.Conn.Sp.Instance
conv.Source = sourceProfile.Driver
//handle fetching schema differently for sharded migrations, we only connect to the primary shard to
//fetch the schema. We reuse the SourceProfileConnection object for this purpose.
var infoSchema common.InfoSchema
Expand Down Expand Up @@ -96,7 +100,11 @@ func (sads *SchemaFromSourceImpl) schemaFromDatabase(migrationProjectId string,
additionalSchemaAttributes := internal.AdditionalSchemaAttributes{
IsSharded: isSharded,
}
return conv, processSchema.ProcessSchema(conv, infoSchema, common.DefaultWorkers, additionalSchemaAttributes, &common.SchemaToSpannerImpl{}, &common.UtilsOrderImpl{}, &common.InfoSchemaImpl{})

ctx := context.Background()
expressionVerificationAccessor, _ := expressions_api.NewExpressionVerificationAccessorImpl(ctx, conv.SpProjectId, conv.SpInstanceId)

return conv, processSchema.ProcessSchema(conv, infoSchema, common.DefaultWorkers, additionalSchemaAttributes, &common.SchemaToSpannerImpl{expressionVerificationAccessor}, &common.UtilsOrderImpl{}, &common.InfoSchemaImpl{})
}

func (sads *SchemaFromSourceImpl) SchemaFromDump(driver string, spDialect string, ioHelper *utils.IOStreams, processDump ProcessDumpByDialectInterface) (*internal.Conv, error) {
Expand All @@ -109,6 +117,7 @@ func (sads *SchemaFromSourceImpl) SchemaFromDump(driver string, spDialect string
ioHelper.BytesRead = n
conv := internal.MakeConv()
conv.SpDialect = spDialect
conv.Source = driver
p := internal.NewProgress(n, "Generating schema", internal.Verbose(), false, int(internal.SchemaCreationInProgress))
r := internal.NewReader(bufio.NewReader(f), p)
conv.SetSchemaMode() // Build schema and ignore data in dump.
Expand Down Expand Up @@ -159,6 +168,9 @@ func (sads *DataFromSourceImpl) dataFromCSV(ctx context.Context, sourceProfile p
return nil, fmt.Errorf("dbName is mandatory in target-profile for csv source")
}
conv.SpDialect = targetProfile.Conn.Sp.Dialect
conv.SpProjectId = targetProfile.Conn.Sp.Project
conv.SpInstanceId = targetProfile.Conn.Sp.Instance
conv.Source = sourceProfile.Driver
dialect, err := targetProfile.FetchTargetDialect(ctx)
if err != nil {
return nil, fmt.Errorf("could not fetch dialect: %v", err)
Expand Down
9 changes: 6 additions & 3 deletions conversion/conversion_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/constants"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/metrics"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/utils"
"github.com/GoogleCloudPlatform/spanner-migration-tool/expressions_api"
"github.com/GoogleCloudPlatform/spanner-migration-tool/internal"
"github.com/GoogleCloudPlatform/spanner-migration-tool/logger"
"github.com/GoogleCloudPlatform/spanner-migration-tool/profiles"
Expand All @@ -45,7 +46,9 @@ type ProcessDumpByDialectInterface interface{
ProcessDump(driver string, conv *internal.Conv, r *internal.Reader) error
}

type ProcessDumpByDialectImpl struct{}
type ProcessDumpByDialectImpl struct{
ExpressionVerificationAccessor expressions_api.ExpressionVerificationAccessor
}

type PopulateDataConvInterface interface{
populateDataConv(conv *internal.Conv, config writer.BatchWriterConfig, client *sp.Client) *writer.BatchWriter
Expand Down Expand Up @@ -88,9 +91,9 @@ func getSeekable(f *os.File) (*os.File, int64, error) {
func (pdd *ProcessDumpByDialectImpl) ProcessDump(driver string, conv *internal.Conv, r *internal.Reader) error {
switch driver {
case constants.MYSQLDUMP:
return common.ProcessDbDump(conv, r, mysql.DbDumpImpl{})
return common.ProcessDbDump(conv, r, mysql.DbDumpImpl{pdd.ExpressionVerificationAccessor})
case constants.PGDUMP:
return common.ProcessDbDump(conv, r, postgres.DbDumpImpl{})
return common.ProcessDbDump(conv, r, postgres.DbDumpImpl{pdd.ExpressionVerificationAccessor})
default:
return fmt.Errorf("process dump for driver %s not supported", driver)
}
Expand Down
111 changes: 108 additions & 3 deletions expressions_api/expression_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"sync"

spannerclient "github.com/GoogleCloudPlatform/spanner-migration-tool/accessors/clients/spanner/client"
spanneraccessor "github.com/GoogleCloudPlatform/spanner-migration-tool/accessors/spanner"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/constants"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/task"
Expand All @@ -18,22 +19,50 @@ const THREAD_POOL = 500
type ExpressionVerificationAccessor interface {
//Batch API which parallelizes expression verification calls
VerifyExpressions(ctx context.Context, verifyExpressionsInput internal.VerifyExpressionsInput) internal.VerifyExpressionsOutput
RefreshSpannerClient(ctx context.Context, project string, instance string) error
}

type ExpressionVerificationAccessorImpl struct {
SpannerAccessor *spanneraccessor.SpannerAccessorImpl
}

func NewExpressionVerificationAccessorImpl(ctx context.Context, project string, instance string) (*ExpressionVerificationAccessorImpl, error) {
spannerAccessor, err := spanneraccessor.NewSpannerAccessorClientImplWithSpannerClient(ctx, fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instance, "smt-staging-db"))
if err != nil {
return nil, err
var spannerAccessor *spanneraccessor.SpannerAccessorImpl
var err error
if project != "" && instance != "" {
spannerAccessor, err = spanneraccessor.NewSpannerAccessorClientImplWithSpannerClient(ctx, fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instance, constants.TEMP_DB))
if err != nil {
return nil, err
}
} else {
spannerAccessor, err = spanneraccessor.NewSpannerAccessorClientImpl(ctx)
if err != nil {
return nil, err
}
}
return &ExpressionVerificationAccessorImpl{
SpannerAccessor: spannerAccessor,
}, nil
}

// APIs to verify and process Spanner DLL features such as Default Values, Check Constraints
type DDLVerifier interface {
VerifySpannerDDL(conv *internal.Conv, expressionDetails []internal.ExpressionDetail) (internal.VerifyExpressionsOutput, error)
GetSourceExpressionDetails(conv *internal.Conv, tableIds []string) []internal.ExpressionDetail
GetSpannerExpressionDetails(conv *internal.Conv, tableIds []string) []internal.ExpressionDetail
RefreshSpannerClient(ctx context.Context, project string, instance string) error
}
type DDLVerifierImpl struct {
Expressions ExpressionVerificationAccessor
}

func NewDDLVerifierImpl(ctx context.Context, project string, instance string) (*DDLVerifierImpl, error) {
expVerifier, err := NewExpressionVerificationAccessorImpl(ctx, project, instance)
return &DDLVerifierImpl{
Expressions: expVerifier,
}, err
}

func (ev *ExpressionVerificationAccessorImpl) VerifyExpressions(ctx context.Context, verifyExpressionsInput internal.VerifyExpressionsInput) internal.VerifyExpressionsOutput {
err := ev.validateRequest(verifyExpressionsInput)
if err != nil {
Expand Down Expand Up @@ -79,6 +108,15 @@ func (ev *ExpressionVerificationAccessorImpl) VerifyExpressions(ctx context.Cont
return verifyExpressionsOutput
}

func (ev *ExpressionVerificationAccessorImpl) RefreshSpannerClient(ctx context.Context, project string, instance string) error {
spannerClient, err := spannerclient.NewSpannerClientImpl(ctx, fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instance, constants.TEMP_DB))
if err != nil {
return err
}
ev.SpannerAccessor.SpannerClient = spannerClient
return nil
}

func (ev *ExpressionVerificationAccessorImpl) verifyExpressionInternal(expressionDetail internal.ExpressionDetail, mutex *sync.Mutex) task.TaskResult[internal.ExpressionVerificationOutput] {
var sqlStatement string
switch expressionDetail.Type {
Expand Down Expand Up @@ -122,10 +160,77 @@ func (ev *ExpressionVerificationAccessorImpl) removeExpressions(inputConv *inter
//TODO: Implement similar checks for DEFAULT and CHECK constraints as well
convCopy.SpSequences = nil
for _, table := range convCopy.SpSchema {
table.CheckConstraints = []ddl.CheckConstraint{}
convCopy.SpSchema[table.Id] = table

for colName, colDef := range table.ColDefs {
colDef.AutoGen = ddl.AutoGenCol{}
table.ColDefs[colName] = colDef
}
}
return convCopy, nil
}

func (ddlv *DDLVerifierImpl) VerifySpannerDDL(conv *internal.Conv, expressionDetails []internal.ExpressionDetail) (internal.VerifyExpressionsOutput, error) {
ctx := context.Background()
verifyExpressionsInput := internal.VerifyExpressionsInput{
Conv: conv,
Source: conv.Source,
ExpressionDetailList: expressionDetails,
}
verificationResults := ddlv.Expressions.VerifyExpressions(ctx, verifyExpressionsInput)

return verificationResults, verificationResults.Err
}

func (ddlv *DDLVerifierImpl) GetSourceExpressionDetails(conv *internal.Conv, tableIds []string) []internal.ExpressionDetail {
expressionDetails := []internal.ExpressionDetail{}
// Collect default values for verification
for _, tableId := range tableIds {
srcTable := conv.SrcSchema[tableId]
for _, srcColId := range srcTable.ColIds {
srcCol := srcTable.ColDefs[srcColId]
if srcCol.DefaultValue.IsPresent {
defaultValueExp := internal.ExpressionDetail{
ReferenceElement: internal.ReferenceElement{
Name: conv.SpSchema[tableId].ColDefs[srcColId].T.Name,
},
ExpressionId: srcCol.DefaultValue.Value.ExpressionId,
Expression: srcCol.DefaultValue.Value.Statement,
Type: "DEFAULT",
Metadata: map[string]string{"TableId": tableId, "ColId": srcColId},
}
expressionDetails = append(expressionDetails, defaultValueExp)
}
}
}
return expressionDetails
}

func (ddlv *DDLVerifierImpl) GetSpannerExpressionDetails(conv *internal.Conv, tableIds []string) []internal.ExpressionDetail {
expressionDetails := []internal.ExpressionDetail{}
// Collect default values for verification
for _, tableId := range tableIds {
spTable := conv.SpSchema[tableId]
for _, spColId := range spTable.ColIds {
spCol := spTable.ColDefs[spColId]
if spCol.DefaultValue.IsPresent {
defaultValueExp := internal.ExpressionDetail{
ReferenceElement: internal.ReferenceElement{
Name: conv.SpSchema[tableId].ColDefs[spColId].T.Name,
},
ExpressionId: spCol.DefaultValue.Value.ExpressionId,
Expression: spCol.DefaultValue.Value.Statement,
Type: "DEFAULT",
Metadata: map[string]string{"TableId": tableId, "ColId": spColId},
}
expressionDetails = append(expressionDetails, defaultValueExp)
}
}
}
return expressionDetails
}

func (ddlv *DDLVerifierImpl) RefreshSpannerClient(ctx context.Context, project string, instance string) error {
return ddlv.Expressions.RefreshSpannerClient(ctx, project, instance)
}
Loading