cloudspannerecosystem / spanner-cli

Interactive command line tool for Cloud Spanner
Apache License 2.0
230 stars 28 forks source link

Add support for RENAME TABLE and table synonyms #165

Closed takabow closed 8 months ago

takabow commented 8 months ago

This PR includes This PR adds support for the following, related to the recently added table rename feature in Spanner.

Examples:

spanner> SHOW TABLES;
+----------------------+
| Tables_in_example-db |
+----------------------+
| Album                |
+----------------------+
1 rows in set (0.03 sec)

spanner> ALTER TABLE Album RENAME TO AlbumDetails, ADD SYNONYM Album;
Query OK, 0 rows affected (12.66 sec)

spanner> SHOW TABLES;
+----------------------+
| Tables_in_example-db |
+----------------------+
| Album                |
| AlbumDetails         |
+----------------------+
2 rows in set (0.02 sec)

spanner> RENAME TABLE AlbumDetails TO AlbumDetails2;
Query OK, 0 rows affected (9.58 sec)

spanner> SHOW TABLES;
+----------------------+
| Tables_in_example-db |
+----------------------+
| Album                |
| AlbumDetails2        |
+----------------------+
2 rows in set (0.02 sec)
takabow commented 8 months ago

The current behavior of SHOW TABLES displays both tables and views from INFORMATION_SCHEMA.TABLES. To match this behavior, synonyms are also displayed. If necessary, we may adopt the SHOW FULL TABLE syntax from MySQL.

spanner> SHOW TABLES;
+----------------------+
| Tables_in_example-db |
+----------------------+
| Album                |    # Synonym
| AlbumDetails         |    # Renamed table
+----------------------+
2 rows in set (0.02 sec)