fix(mysql): show scheduled events in the sidebar
This commit is contained in:
1 parent
5011468a9a
commit
2b11af94ba
26 files changed
+137
-33
No files matched your search
@@ -347,6 +347,7 @@ fn object_type_keyword(object_type: &ObjectSourceKind) -> &'static str {
|
||||
ObjectSourceKind::Procedure => "PROCEDURE",
|
||||
ObjectSourceKind::Function => "FUNCTION",
|
||||
ObjectSourceKind::Trigger => "TRIGGER",
|
||||
ObjectSourceKind::Event => "EVENT",
|
||||
ObjectSourceKind::Sequence => "SEQUENCE",
|
||||
ObjectSourceKind::Synonym => "SYNONYM",
|
||||
ObjectSourceKind::Package => "PACKAGE",
|
||||
|
||||
@@ -2771,16 +2771,16 @@ mod tests {
|
||||
dameng_object_statistics_rows_only_sql, dameng_object_statistics_user_segments_sql, deduplicate_column_infos,
|
||||
ephemeral_agent_metadata_session_id, external_driver_uses_mysql_ddl, filter_mongodb_agent_collections,
|
||||
filter_mysql_system_databases_for_config, filter_object_infos, filter_table_infos, filter_visible_schema_names,
|
||||
gaussdb_m_view_object_source_sql, gbase8a_object_statistics_sql, is_agent_postgres_metadata_fallback_config,
|
||||
is_mysql_external_driver_config, is_retryable_metadata_error, metadata_error_action,
|
||||
metadata_name_or_comment_matches, mysql_database_list_timeout, mysql_external_driver_ddl_from_query_result,
|
||||
mysql_external_driver_ddl_sql, mysql_object_source_ddl_column_index, mysql_object_source_sql,
|
||||
mysql_table_list_source_for_config, mysql_table_metadata_catalog, normalize_information_schema_table_type,
|
||||
oracle_columns_from_query_result, oracle_columns_sql, oracle_object_statistics_dba_segments_sql,
|
||||
oracle_object_statistics_from_query_result, oracle_object_statistics_rows_only_sql,
|
||||
oracle_object_statistics_sql, oracle_object_statistics_user_segments_sql,
|
||||
oracle_table_comment_from_query_result, oracle_table_comment_sql, oracle_table_comments_sql,
|
||||
presto_like_columns_from_query_result, presto_like_information_schema_columns_sql,
|
||||
finalize_object_source, gaussdb_m_view_object_source_sql, gbase8a_object_statistics_sql,
|
||||
is_agent_postgres_metadata_fallback_config, is_mysql_external_driver_config, is_retryable_metadata_error,
|
||||
metadata_error_action, metadata_name_or_comment_matches, mysql_database_list_timeout,
|
||||
mysql_external_driver_ddl_from_query_result, mysql_external_driver_ddl_sql,
|
||||
mysql_object_source_ddl_column_index, mysql_object_source_sql, mysql_table_list_source_for_config,
|
||||
mysql_table_metadata_catalog, normalize_information_schema_table_type, oracle_columns_from_query_result,
|
||||
oracle_columns_sql, oracle_object_statistics_dba_segments_sql, oracle_object_statistics_from_query_result,
|
||||
oracle_object_statistics_rows_only_sql, oracle_object_statistics_sql,
|
||||
oracle_object_statistics_user_segments_sql, oracle_table_comment_from_query_result, oracle_table_comment_sql,
|
||||
oracle_table_comments_sql, presto_like_columns_from_query_result, presto_like_information_schema_columns_sql,
|
||||
presto_like_information_schema_tables_sql, presto_like_tables_from_query_result, replace_metadata_runtime,
|
||||
should_query_oracle_columns_via_sql_first, table_comments_from_query_result, table_name_filter_matches,
|
||||
tdengine_table_comment_like_pattern, tdengine_table_comment_sql, tdengine_table_comments_sql,
|
||||
@@ -3345,6 +3345,27 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_object_source_sql_emits_show_create_event() {
|
||||
assert_eq!(
|
||||
mysql_object_source_sql("tenant_db", "event_daily_sync", &db::ObjectSourceKind::Event),
|
||||
"SHOW CREATE EVENT `tenant_db`.`event_daily_sync`"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_event_object_source_is_read_only() {
|
||||
let source = finalize_object_source(db::ObjectSource {
|
||||
name: "event_daily_sync".to_string(),
|
||||
object_type: db::ObjectSourceKind::Event,
|
||||
schema: None,
|
||||
source: "CREATE EVENT event_daily_sync ON SCHEDULE EVERY 1 DAY DO SELECT 1".to_string(),
|
||||
editable: None,
|
||||
});
|
||||
|
||||
assert_eq!(source.editable, Some(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_object_source_sql_emits_show_create_materialized_view() {
|
||||
// Regression for the review comment: Doris / StarRocks ride on the MySQL
|
||||
@@ -3373,6 +3394,10 @@ mod tests {
|
||||
assert_eq!(mysql_object_source_ddl_column_index(&db::ObjectSourceKind::Procedure), 2);
|
||||
assert_eq!(mysql_object_source_ddl_column_index(&db::ObjectSourceKind::Function), 2);
|
||||
assert_eq!(mysql_object_source_ddl_column_index(&db::ObjectSourceKind::Trigger), 2);
|
||||
// SHOW CREATE EVENT returns (Event, sql_mode, time_zone, Create Event, …) —
|
||||
// one extra time_zone column before the DDL, verified against a real MySQL
|
||||
// 8.0 instance (`SHOW CREATE EVENT` for a live event).
|
||||
assert_eq!(mysql_object_source_ddl_column_index(&db::ObjectSourceKind::Event), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -7235,6 +7260,7 @@ fn sqlite_object_type(kind: &db::ObjectSourceKind) -> &'static str {
|
||||
db::ObjectSourceKind::Procedure
|
||||
| db::ObjectSourceKind::Function
|
||||
| db::ObjectSourceKind::Trigger
|
||||
| db::ObjectSourceKind::Event
|
||||
| db::ObjectSourceKind::Sequence
|
||||
| db::ObjectSourceKind::Synonym
|
||||
| db::ObjectSourceKind::Package
|
||||
@@ -7250,7 +7276,8 @@ fn sqlserver_object_type_filter(kind: &db::ObjectSourceKind) -> &'static str {
|
||||
db::ObjectSourceKind::Procedure => "'P'",
|
||||
db::ObjectSourceKind::Function => "'FN','IF','TF','FS','FT'",
|
||||
db::ObjectSourceKind::Trigger => "'TR'",
|
||||
db::ObjectSourceKind::Sequence
|
||||
db::ObjectSourceKind::Event
|
||||
| db::ObjectSourceKind::Sequence
|
||||
| db::ObjectSourceKind::Synonym
|
||||
| db::ObjectSourceKind::Package
|
||||
| db::ObjectSourceKind::PackageBody
|
||||
@@ -7488,6 +7515,7 @@ fn postgres_object_source_sql_inner(
|
||||
)
|
||||
}
|
||||
db::ObjectSourceKind::Trigger
|
||||
| db::ObjectSourceKind::Event
|
||||
| db::ObjectSourceKind::Synonym
|
||||
| db::ObjectSourceKind::Package
|
||||
| db::ObjectSourceKind::PackageBody
|
||||
@@ -7503,6 +7531,7 @@ pub fn oracle_object_source_sql(schema: &str, name: &str, kind: &db::ObjectSourc
|
||||
db::ObjectSourceKind::Procedure => "PROCEDURE",
|
||||
db::ObjectSourceKind::Function => "FUNCTION",
|
||||
db::ObjectSourceKind::Trigger => "TRIGGER",
|
||||
db::ObjectSourceKind::Event => "EVENT",
|
||||
db::ObjectSourceKind::Sequence => "SEQUENCE",
|
||||
db::ObjectSourceKind::Synonym => "SYNONYM",
|
||||
db::ObjectSourceKind::Package => "PACKAGE",
|
||||
@@ -7559,6 +7588,7 @@ pub fn mysql_object_source_sql(database: &str, name: &str, kind: &db::ObjectSour
|
||||
db::ObjectSourceKind::Procedure => format!("SHOW CREATE PROCEDURE {qualified_name}"),
|
||||
db::ObjectSourceKind::Function => format!("SHOW CREATE FUNCTION {qualified_name}"),
|
||||
db::ObjectSourceKind::Trigger => format!("SHOW CREATE TRIGGER {qualified_name}"),
|
||||
db::ObjectSourceKind::Event => format!("SHOW CREATE EVENT {qualified_name}"),
|
||||
db::ObjectSourceKind::Sequence
|
||||
| db::ObjectSourceKind::Synonym
|
||||
| db::ObjectSourceKind::Package
|
||||
@@ -7585,6 +7615,8 @@ pub fn mysql_object_source_sql(database: &str, name: &str, kind: &db::ObjectSour
|
||||
/// `(Name, DDL)` → DDL at index `1`.
|
||||
/// - `SHOW CREATE PROCEDURE`, `SHOW CREATE FUNCTION`, `SHOW CREATE TRIGGER` →
|
||||
/// `(Name, sql_mode, DDL, …)` → DDL at index `2`.
|
||||
/// - `SHOW CREATE EVENT` → `(Event, sql_mode, time_zone, Create Event, …)` →
|
||||
/// DDL at index `3` (it has an extra `time_zone` column before the DDL).
|
||||
///
|
||||
/// Encoded as a function so the index can be unit-tested without a live DB.
|
||||
pub(crate) fn mysql_object_source_ddl_column_index(kind: &db::ObjectSourceKind) -> usize {
|
||||
@@ -7599,6 +7631,7 @@ pub(crate) fn mysql_object_source_ddl_column_index(kind: &db::ObjectSourceKind)
|
||||
| db::ObjectSourceKind::PackageBody
|
||||
| db::ObjectSourceKind::Type
|
||||
| db::ObjectSourceKind::TypeBody => 2,
|
||||
db::ObjectSourceKind::Event => 3,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7804,7 +7837,7 @@ pub async fn get_object_source_core(
|
||||
signature: Option<&str>,
|
||||
relation_name: Option<&str>,
|
||||
) -> Result<db::ObjectSource, String> {
|
||||
let mut source = retry_metadata_connection(state, connection_id, Some(database), || {
|
||||
let source = retry_metadata_connection(state, connection_id, Some(database), || {
|
||||
get_object_source_once(
|
||||
state,
|
||||
connection_id,
|
||||
@@ -7817,10 +7850,17 @@ pub async fn get_object_source_core(
|
||||
)
|
||||
})
|
||||
.await?;
|
||||
Ok(finalize_object_source(source))
|
||||
}
|
||||
|
||||
fn finalize_object_source(mut source: db::ObjectSource) -> db::ObjectSource {
|
||||
if matches!(source.object_type, db::ObjectSourceKind::Procedure | db::ObjectSourceKind::Function) {
|
||||
source.source = normalize_routine_object_source(source.source);
|
||||
}
|
||||
Ok(source)
|
||||
if matches!(source.object_type, db::ObjectSourceKind::Event) {
|
||||
source.editable = Some(false);
|
||||
}
|
||||
source
|
||||
}
|
||||
|
||||
async fn get_object_source_once(
|
||||
|
||||
@@ -7468,9 +7468,10 @@ where
|
||||
| db::ObjectSourceKind::Synonym
|
||||
| db::ObjectSourceKind::Package
|
||||
| db::ObjectSourceKind::PackageBody => object.source.clone(),
|
||||
db::ObjectSourceKind::Trigger | db::ObjectSourceKind::Type | db::ObjectSourceKind::TypeBody => {
|
||||
object.source.clone()
|
||||
}
|
||||
db::ObjectSourceKind::Trigger
|
||||
| db::ObjectSourceKind::Event
|
||||
| db::ObjectSourceKind::Type
|
||||
| db::ObjectSourceKind::TypeBody => object.source.clone(),
|
||||
};
|
||||
let statements = build_executable_object_source_statements(EditableObjectSourceSqlInput {
|
||||
database_type: DatabaseType::Postgres,
|
||||
|
||||
@@ -122,6 +122,7 @@ pub enum ObjectSourceKind {
|
||||
Procedure,
|
||||
Function,
|
||||
Trigger,
|
||||
Event,
|
||||
Sequence,
|
||||
Synonym,
|
||||
Package,
|
||||
|
||||
Reference in new issue
Block a user