HarbourBridge is a stand-alone open source tool for Cloud Spanner evaluation and migration. This README provides details of the HarbourBridge schema assistant, which supports schema customization. For general HarbourBridge information see this README.
The following examples assume harbourbridge
alias has been setup as
following.
git clone https://github.com/cloudspannerecosystem/harbourbridge
cd harbourbridge
alias harbourbridge="go run github.com/cloudspannerecosystem/harbourbridge"
HarbourBridge's Web API feature can be used with all the driver modes available, using mysql or postgres dump or direct connection.
To generate the HarbourBridge binary, run:
make build
To start HarbourBridge web server, run:
./harbourbridge web
The UI will launched at http://localhost:8080/.
For more details on how to use the UI, click on the help
button on the top right corner of the page.
Note:
The pg_dump
and mysqldump
drivers cannot be used for data migration if the
Spanner schema has interleaved tables. Note that the postgres
or mysql
drivers
do not have this restriction -- consider using these as an alternative.
These are the REST APIs and their details:
/connect
is a POST API used to configure direct connection to a database.
The request body contains connection details and the driver name.
POST
Connection information along with driver name.
Example
{
"Driver": "postgres",
"Host": "localhost",
"Port": "5432",
"Database": "dbname",
"User": "user",
"Password": "password"
}
No response body is returned.
(1) /convert/infoschema
is a GET API followed by /connect
API to convert using
infoschema mode. It returns the schema conversion state in json format.
GET
No request body is needed.
Conv struct in JSON format.
(2) /convert/dump
is a POST API used to perform schema conversion on a dump file.
The request body contains the path to the dump file.
POST
Provide driver and path to dump file.
Example
{
"Driver": "postgres",
"Path": "/path/to/dumpFile"
}
Conv struct in JSON format.
/ddl
is a GET API which must be used after using conversion APIs (i.e, /connect
or /convert
). This API returns the DDL statements of the converted schema.
GET
No request body is needed.
Table wise DDL statements.
Example
{
"Albums": "--\n-- Spanner schema for source table Albums\n--\nCREATE TABLE
Albums (\n SingerId INT64 NOT NULL, -- From: SingerId smallint(6)\n
AlbumId INT64 NOT NULL, -- From: AlbumId smallint(6)\n AlbumTitle STRING(50)
-- From: AlbumTitle varchar(50)\n) PRIMARY KEY (SingerId, AlbumId)"
}
(1) /session
is a GET API which returns the schema conversion state in json format.
It also create a file with suffix .session.json
in the frontend/
folder.
GET
No request body is needed.
Session file info with driver name.
Example
{
"Driver": "postgres",
"FilePath": "/path/to/sessionFile",
"FileName": "sessionFile.session.json",
"CreatedAt": "Thu, 04 Feb 2021 18:10:32 IST"
}
(2) /session/resume
is a POST API which can be used to resume a previous session.
The request body contains the path to the previous session. Note that sessions are
created by the /session
API.
POST
Provide driver and session file path.
Example
{
"driver": "postgres",
"path": "/path/to/sessionFile",
"fileName": "sessionFile.session.json"
}
No response body is returned.
/summary
is a GET API which returns a table-by-table report of the conversion.
GET
No request body is needed.
Table wise summary of conversion.
Example
{
"Albums": "Note\n1) Some columns will consume more storage in Spanner
e.g. for column 'AlbumId', source DB type smallint(6) is mapped to Spanner
type int64.\n\n"
}
/overview
is a GET API which returns the overview of the conversion.
GET
No request body is needed.
Overall summary of conversion in string format.
/conversion
is a GET API which returns table wise rate of conversion which is
encoded in color values.
GET
No request body is needed.
Table wise rate of conversion encoded in color values.
Example
{
"Albums": "GREEN",
"Singers": "BLUE",
"Userinfo": "ORANGE"
}
(1) /typemap
is a GET API which returns a map that, for each source type,
provides the potential Spanner types that can be used for that source type.
This map can be used for customization of type mapping in the UI.
GET
No request body is needed.
Map from each source type to the list of possible Spanner types and issues.
Example
{
"smallint": [
{
"T": "INT64",
"Brief": "Some columns will consume more storage in Spanner"
},
{
"T": "STRING",
"Brief": "Some columns will consume more storage in Spanner"
}
],
"varchar": [
{
"T": "BYTES",
"Brief": ""
},
{
"T": "STRING",
"Brief": ""
}
]
}
(2) /typemap/global
is a POST API to customize schema conversion on global level.
The request body contains a map from source type to Spanner type in json format.
POST
Map from source type to Spanner type.
Example
{
"smallint": "STRING",
"varchar": "BYTES"
}
Updated Conv struct in JSON format.
(3) /typemap/table?table=<table_name>
is a POST API which performs following
operations on a single table.
- Remove column
- Rename column
- Remove or Add primary key
- Update type of column
- Remove or Add NOT NULL constraint
POST
Column wise actions to be performed with following possible values for each field.
- Removed : true/false
- Rename : New name or empty string
- PK : "" | "ADDED" | "REMOVED"
- NotNull : "" | "ADDED" | "REMOVED"
- ToType : New Spanner type or empty string
Example
{
"UpdateCols": {
"AlbumTitle": {
"Removed": false,
"Rename": "AlbumName",
"PK": "",
"NotNull": "ADDED",
"ToType": "BYTES"
}
}
}
Updated Conv struct in JSON format.
/report
is a GET API which generates report file and returns file path.
GET
No request body is needed.
Path to report file.
Example
/path/to/reportfile.report.txt
/schema
is a GET API which generates schema file and returns file path.
GET
No request body is needed.
Path to schema file.
Example
/path/to/schemafile.schema.txt
/setparent?table=<table_name>
is a GET API which checks whether it is
possible to convert a table into a Spanner interleaved table. If this conversion is possible,
then the schema is changed and the parent table name is returned.
If the conversion is not possible, a failure message is returned.
GET
No request body is needed.
If it is possible to make given table interleaved, it will return with table name of parent.
Example
{
"Possible": true,
"Parent": "Singers",
"Comment": ""
}
If it is not possible to interleave given table, it will return with the reason of why it failed.
Example
{
"Possible": false,
"Parent": "",
"Comment": "No valid prefix"
}
/drop/fk?table=<table_name>&pos=<position>
is a GET API which takes table name
and array position of foreign key in query params. It drops foreign key at given
position for given table name.
GET
No request body is needed.
Updated Conv struct in JSON format.
/drop/secondaryindex?table=<table_name>&pos=<position>
is a GET API which takes
table name and array position of secondary index in query params. It drops secondary
index at given position for given table name.
GET
No request body is needed.
Updated Conv struct in JSON format.