@@ -1131,10 +1131,6 @@ impl CatalogController {
1131
1131
if obj. schema_id == Some ( new_schema) {
1132
1132
return Ok ( IGNORED_NOTIFICATION_VERSION ) ;
1133
1133
}
1134
-
1135
- let mut obj = obj. into_active_model ( ) ;
1136
- obj. schema_id = Set ( Some ( new_schema) ) ;
1137
- let obj = obj. update ( & txn) . await ?;
1138
1134
let database_id = obj. database_id . unwrap ( ) ;
1139
1135
1140
1136
let mut relations = vec ! [ ] ;
@@ -1145,9 +1141,16 @@ impl CatalogController {
1145
1141
. await ?
1146
1142
. ok_or_else ( || MetaError :: catalog_id_not_found ( "table" , object_id) ) ?;
1147
1143
check_relation_name_duplicate ( & table. name , database_id, new_schema, & txn) . await ?;
1144
+ let ( associated_src_id, table_type) =
1145
+ ( table. optional_associated_source_id , table. table_type ) ;
1146
+
1147
+ let mut obj = obj. into_active_model ( ) ;
1148
+ obj. schema_id = Set ( Some ( new_schema) ) ;
1149
+ let obj = obj. update ( & txn) . await ?;
1150
+ relations. push ( PbRelationInfo :: Table ( ObjectModel ( table, obj) . into ( ) ) ) ;
1148
1151
1149
1152
// associated source.
1150
- if let Some ( associated_source_id) = table . optional_associated_source_id {
1153
+ if let Some ( associated_source_id) = associated_src_id {
1151
1154
let src_obj = object:: ActiveModel {
1152
1155
oid : Set ( associated_source_id as _ ) ,
1153
1156
schema_id : Set ( Some ( new_schema) ) ,
@@ -1168,7 +1171,7 @@ impl CatalogController {
1168
1171
let ( index_ids, ( index_names, mut table_ids) ) : (
1169
1172
Vec < IndexId > ,
1170
1173
( Vec < String > , Vec < TableId > ) ,
1171
- ) = if table . table_type == TableType :: Table {
1174
+ ) = if table_type == TableType :: Table {
1172
1175
Index :: find ( )
1173
1176
. select_only ( )
1174
1177
. columns ( [
@@ -1186,7 +1189,6 @@ impl CatalogController {
1186
1189
} else {
1187
1190
( vec ! [ ] , ( vec ! [ ] , vec ! [ ] ) )
1188
1191
} ;
1189
- relations. push ( PbRelationInfo :: Table ( ObjectModel ( table, obj) . into ( ) ) ) ;
1190
1192
1191
1193
// internal tables.
1192
1194
let internal_tables: Vec < TableId > = Table :: find ( )
@@ -1220,18 +1222,6 @@ impl CatalogController {
1220
1222
. await ?;
1221
1223
}
1222
1224
1223
- if !index_ids. is_empty ( ) {
1224
- let index_objs = Index :: find ( )
1225
- . find_also_related ( Object )
1226
- . filter ( index:: Column :: IndexId . is_in ( index_ids) )
1227
- . all ( & txn)
1228
- . await ?;
1229
- for ( index, index_obj) in index_objs {
1230
- relations. push ( PbRelationInfo :: Index (
1231
- ObjectModel ( index, index_obj. unwrap ( ) ) . into ( ) ,
1232
- ) ) ;
1233
- }
1234
- }
1235
1225
if !table_ids. is_empty ( ) {
1236
1226
let table_objs = Table :: find ( )
1237
1227
. find_also_related ( Object )
@@ -1244,13 +1234,29 @@ impl CatalogController {
1244
1234
) ) ;
1245
1235
}
1246
1236
}
1237
+ if !index_ids. is_empty ( ) {
1238
+ let index_objs = Index :: find ( )
1239
+ . find_also_related ( Object )
1240
+ . filter ( index:: Column :: IndexId . is_in ( index_ids) )
1241
+ . all ( & txn)
1242
+ . await ?;
1243
+ for ( index, index_obj) in index_objs {
1244
+ relations. push ( PbRelationInfo :: Index (
1245
+ ObjectModel ( index, index_obj. unwrap ( ) ) . into ( ) ,
1246
+ ) ) ;
1247
+ }
1248
+ }
1247
1249
}
1248
1250
ObjectType :: Source => {
1249
1251
let source = Source :: find_by_id ( object_id)
1250
1252
. one ( & txn)
1251
1253
. await ?
1252
1254
. ok_or_else ( || MetaError :: catalog_id_not_found ( "source" , object_id) ) ?;
1253
1255
check_relation_name_duplicate ( & source. name , database_id, new_schema, & txn) . await ?;
1256
+
1257
+ let mut obj = obj. into_active_model ( ) ;
1258
+ obj. schema_id = Set ( Some ( new_schema) ) ;
1259
+ let obj = obj. update ( & txn) . await ?;
1254
1260
relations. push ( PbRelationInfo :: Source ( ObjectModel ( source, obj) . into ( ) ) ) ;
1255
1261
}
1256
1262
ObjectType :: Sink => {
@@ -1259,6 +1265,10 @@ impl CatalogController {
1259
1265
. await ?
1260
1266
. ok_or_else ( || MetaError :: catalog_id_not_found ( "sink" , object_id) ) ?;
1261
1267
check_relation_name_duplicate ( & sink. name , database_id, new_schema, & txn) . await ?;
1268
+
1269
+ let mut obj = obj. into_active_model ( ) ;
1270
+ obj. schema_id = Set ( Some ( new_schema) ) ;
1271
+ let obj = obj. update ( & txn) . await ?;
1262
1272
relations. push ( PbRelationInfo :: Sink ( ObjectModel ( sink, obj) . into ( ) ) ) ;
1263
1273
1264
1274
// internal tables.
@@ -1298,16 +1308,30 @@ impl CatalogController {
1298
1308
. await ?
1299
1309
. ok_or_else ( || MetaError :: catalog_id_not_found ( "view" , object_id) ) ?;
1300
1310
check_relation_name_duplicate ( & view. name , database_id, new_schema, & txn) . await ?;
1311
+
1312
+ let mut obj = obj. into_active_model ( ) ;
1313
+ obj. schema_id = Set ( Some ( new_schema) ) ;
1314
+ let obj = obj. update ( & txn) . await ?;
1301
1315
relations. push ( PbRelationInfo :: View ( ObjectModel ( view, obj) . into ( ) ) ) ;
1302
1316
}
1303
1317
ObjectType :: Function => {
1304
1318
let function = Function :: find_by_id ( object_id)
1305
1319
. one ( & txn)
1306
1320
. await ?
1307
1321
. ok_or_else ( || MetaError :: catalog_id_not_found ( "function" , object_id) ) ?;
1308
- let pb_function: PbFunction = ObjectModel ( function, obj) . into ( ) ;
1322
+
1323
+ let mut pb_function: PbFunction = ObjectModel ( function, obj) . into ( ) ;
1324
+ pb_function. schema_id = new_schema as _ ;
1309
1325
check_function_signature_duplicate ( & pb_function, & txn) . await ?;
1310
1326
1327
+ object:: ActiveModel {
1328
+ oid : Set ( object_id) ,
1329
+ schema_id : Set ( Some ( new_schema) ) ,
1330
+ ..Default :: default ( )
1331
+ }
1332
+ . update ( & txn)
1333
+ . await ?;
1334
+
1311
1335
txn. commit ( ) . await ?;
1312
1336
let version = self
1313
1337
. notify_frontend (
@@ -1322,9 +1346,19 @@ impl CatalogController {
1322
1346
. one ( & txn)
1323
1347
. await ?
1324
1348
. ok_or_else ( || MetaError :: catalog_id_not_found ( "connection" , object_id) ) ?;
1325
- let pb_connection: PbConnection = ObjectModel ( connection, obj) . into ( ) ;
1349
+
1350
+ let mut pb_connection: PbConnection = ObjectModel ( connection, obj) . into ( ) ;
1351
+ pb_connection. schema_id = new_schema as _ ;
1326
1352
check_connection_name_duplicate ( & pb_connection, & txn) . await ?;
1327
1353
1354
+ object:: ActiveModel {
1355
+ oid : Set ( object_id) ,
1356
+ schema_id : Set ( Some ( new_schema) ) ,
1357
+ ..Default :: default ( )
1358
+ }
1359
+ . update ( & txn)
1360
+ . await ?;
1361
+
1328
1362
txn. commit ( ) . await ?;
1329
1363
let version = self
1330
1364
. notify_frontend (
@@ -1337,6 +1371,7 @@ impl CatalogController {
1337
1371
_ => unreachable ! ( "not supported object type: {:?}" , object_type) ,
1338
1372
}
1339
1373
1374
+ txn. commit ( ) . await ?;
1340
1375
let version = self
1341
1376
. notify_frontend (
1342
1377
Operation :: Update ,
@@ -1748,7 +1783,7 @@ impl CatalogController {
1748
1783
let obj = obj. unwrap( ) ;
1749
1784
let old_name = relation. name. clone( ) ;
1750
1785
relation. name = object_name. into( ) ;
1751
- if obj. obj_type != ObjectType :: Index {
1786
+ if obj. obj_type != ObjectType :: View {
1752
1787
relation. definition = alter_relation_rename( & relation. definition, object_name) ;
1753
1788
}
1754
1789
let active_model = $table:: ActiveModel {
@@ -1778,6 +1813,7 @@ impl CatalogController {
1778
1813
. unwrap ( ) ;
1779
1814
index. name = object_name. into ( ) ;
1780
1815
let index_table_id = index. index_table_id ;
1816
+ let old_name = rename_relation ! ( Table , table, table_id, index_table_id) ;
1781
1817
1782
1818
// the name of index and its associated table is the same.
1783
1819
let active_model = index:: ActiveModel {
@@ -1791,7 +1827,7 @@ impl CatalogController {
1791
1827
ObjectModel ( index, obj. unwrap ( ) ) . into ( ) ,
1792
1828
) ) ,
1793
1829
} ) ;
1794
- rename_relation ! ( Table , table , table_id , index_table_id )
1830
+ old_name
1795
1831
}
1796
1832
_ => unreachable ! ( "only relation name can be altered." ) ,
1797
1833
} ;
0 commit comments