@@ -83,14 +83,15 @@ int finalize_alias_table(struct ireq *iq, struct schema_change_type *s,
8383int finalize_rename_table (struct ireq * iq , struct schema_change_type * s ,
8484 tran_type * tran )
8585{
86- struct dbtable * db = s -> db ;
87- char * newname = strdup (s -> newtable );
88- int rc = 0 ;
89- int bdberr = 0 ;
90- char * oldname = NULL ;
91-
9286 assert (s -> kind == SC_RENAMETABLE );
9387
88+ struct dbtable * db = s -> db ;
89+ if (db -> n_rev_constraints > 0 ) {
90+ sc_client_error (s , "Cannot rename a table referenced by a foreign key" );
91+ return -1 ;
92+ }
93+
94+ char * newname = strdup (s -> newtable );
9495 if (!newname ) {
9596 sc_errf (s , "strdup error\n" );
9697 return -1 ;
@@ -103,7 +104,8 @@ int finalize_rename_table(struct ireq *iq, struct schema_change_type *s,
103104 s -> already_finalized = 1 ;
104105
105106 /* renamed table schema gets bumped */
106- rc = table_version_upsert (db , tran , & bdberr );
107+ int bdberr = 0 ;
108+ int rc = table_version_upsert (db , tran , & bdberr );
107109 if (rc ) {
108110 sc_errf (s , "Failed updating table version bdberr %d\n" , bdberr );
109111 goto tran_error ;
@@ -133,7 +135,7 @@ int finalize_rename_table(struct ireq *iq, struct schema_change_type *s,
133135 }
134136
135137 /* fragile, handle with care */
136- oldname = db -> tablename ;
138+ char * oldname = db -> tablename ;
137139 rc = rename_db (db , newname );
138140 if (rc ) {
139141 /* crash the schema change, next master will hopefully have more memory
0 commit comments