cloudspannerecosystem / spanner-dump

Command line tool for exporting a Cloud Spanner database in text format
Apache License 2.0
39 stars 13 forks source link

Exclude Views from dump data #15

Closed yfuruyama closed 3 years ago

yfuruyama commented 3 years ago

Cloud Spanner View doesn't allow DML statements, so spanner-dump must exclude Views from dump data. Currently tables are fetched from INFORMATION_SCHEMA.TABLES and it can contain view tables.

Before:

$ spanner-dump -p ${PROJECT} -i ${INSTANCE} -d ${DATABASE}
CREATE TABLE Singers (                                                                                                                                                                                                                                                    
  SingerId INT64 NOT NULL,                                                                                                           
  FirstName STRING(1024),                                                                                                                                                                                                                                                 
  LastName STRING(1024),                                                                                                                                                                                                                                                  
  SingerInfo BYTES(MAX),                                                                                                             
) PRIMARY KEY(SingerId);                                                                                                             
CREATE VIEW SingerNames SQL SECURITY INVOKER AS SELECT                                                                               
  Singers.SingerId AS SingerId,                                                                                                                                                                                                                                           
  Singers.FirstName || " " || Singers.LastName AS Name                                                                               
FROM Singers;                                                     
INSERT INTO `SingerNames` (`SingerId`, `Name`) VALUES (1, "foo bar");                                                                
INSERT INTO `Singers` (`SingerId`, `FirstName`, `LastName`, `SingerInfo`) VALUES (1, "foo", "bar", NULL);                                                                                                                                                                 

After:

Note that INSERT INTO SingerNames statement is removed.

$ spanner-dump -p ${PROJECT} -i ${INSTANCE} -d ${DATABASE}
CREATE TABLE Singers (                                                                                                               
  SingerId INT64 NOT NULL,                                        
  FirstName STRING(1024),                                                                                                            
  LastName STRING(1024),                                                                                                             
  SingerInfo BYTES(MAX),                                                                                                             
) PRIMARY KEY(SingerId);                                                                                                             
CREATE VIEW SingerNames SQL SECURITY INVOKER AS SELECT                                                                               
  Singers.SingerId AS SingerId,                                                                                                                                                                                                                                           
  Singers.FirstName || " " || Singers.LastName AS Name                                                                                                                                                                                                                    
FROM Singers;
INSERT INTO `Singers` (`SingerId`, `FirstName`, `LastName`, `SingerInfo`) VALUES (1, "foo", "bar", NULL);
yfuruyama commented 3 years ago

@skuruppu Can I ask you for a review when you have a chance? Thanks!

yfuruyama commented 3 years ago

Thanks for the review!