Skip to content

Commit 570be72

Browse files
committed
feat: v17.1.0
1 parent 8ff6698 commit 570be72

File tree

8 files changed

+157
-56
lines changed

8 files changed

+157
-56
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hyperlane-quick-start"
3-
version = "17.0.0"
3+
version = "17.1.0"
44
readme = "README.md"
55
edition = "2024"
66
authors = ["root@ltpp.vip"]

plugin/database/impl.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ impl<T: Clone> ConnectionCache<T> {
149149
}
150150
}
151151

152-
impl PluginType {
152+
impl fmt::Display for PluginType {
153153
#[instrument_trace]
154-
pub fn as_str(&self) -> &'static str {
154+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
155155
match self {
156-
Self::MySQL => "MySQL",
157-
Self::PostgreSQL => "PostgreSQL",
158-
Self::Redis => "Redis",
156+
Self::MySQL => write!(f, "MySQL"),
157+
Self::PostgreSQL => write!(f, "PostgreSQL"),
158+
Self::Redis => write!(f, "Redis"),
159159
}
160160
}
161161
}
@@ -174,13 +174,6 @@ impl FromStr for PluginType {
174174
}
175175
}
176176

177-
impl std::fmt::Display for PluginType {
178-
#[instrument_trace]
179-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
180-
write!(f, "{}", self.as_str())
181-
}
182-
}
183-
184177
impl AutoCreationError {
185178
#[instrument_trace]
186179
pub fn should_continue(&self) -> bool {
@@ -273,6 +266,12 @@ impl DatabaseSchema {
273266
self
274267
}
275268

269+
#[instrument_trace]
270+
pub fn add_init_data(mut self, init_data: String) -> Self {
271+
self.get_mut_init_data().push(init_data);
272+
self
273+
}
274+
276275
#[instrument_trace]
277276
pub fn ordered_tables(&self) -> Vec<&TableSchema> {
278277
let mut ordered: Vec<&TableSchema> = Vec::new();

plugin/database/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use {r#enum::*, r#struct::*};
77
use {super::*, env::*, mysql::*, postgresql::*, redis::*};
88

99
use std::{
10+
fmt,
1011
str::FromStr,
1112
time::{Duration, Instant},
1213
};

plugin/database/struct.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub struct DatabaseSchema {
6565
#[get(pub(crate))]
6666
pub(super) indexes: Vec<String>,
6767
#[get(pub(crate))]
68+
pub(super) init_data: Vec<String>,
69+
#[get(pub(crate))]
6870
pub(super) tables: Vec<TableSchema>,
6971
}
7072

plugin/mysql/impl.rs

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ impl DatabaseConnectionPlugin for MySqlPlugin {
181181
result.get_mut_errors().push(error.to_string());
182182
}
183183
}
184+
if let Err(error) = auto_creator.create_indexes().await {
185+
AutoCreationLogger::log_auto_creation_error(
186+
&error,
187+
"Index creation",
188+
PluginType::MySQL,
189+
Some(instance.get_database().as_str()),
190+
)
191+
.await;
192+
result.get_mut_errors().push(error.to_string());
193+
}
194+
if let Err(error) = auto_creator.init_data().await {
195+
AutoCreationLogger::log_auto_creation_error(
196+
&error,
197+
"Init data",
198+
PluginType::MySQL,
199+
Some(instance.get_database().as_str()),
200+
)
201+
.await;
202+
result.get_mut_errors().push(error.to_string());
203+
}
184204
if let Err(error) = auto_creator.verify_connection().await {
185205
AutoCreationLogger::log_auto_creation_error(
186206
&error,
@@ -407,6 +427,36 @@ impl MySqlAutoCreation {
407427
fn get_database_schema(&self) -> &DatabaseSchema {
408428
&self.schema
409429
}
430+
431+
#[instrument_trace]
432+
async fn create_indexes(&self) -> Result<(), AutoCreationError> {
433+
let connection: DatabaseConnection = self.create_target_connection().await?;
434+
let schema: &DatabaseSchema = self.get_database_schema();
435+
for index_sql in schema.get_indexes() {
436+
if let Err(error) = self.execute_sql(&connection, index_sql).await {
437+
AutoCreationLogger::log_auto_creation_error(
438+
&error,
439+
"Index creation",
440+
PluginType::MySQL,
441+
Some(self.instance.get_database().as_str()),
442+
)
443+
.await;
444+
}
445+
}
446+
for constraint_sql in schema.get_constraints() {
447+
if let Err(error) = self.execute_sql(&connection, constraint_sql).await {
448+
AutoCreationLogger::log_auto_creation_error(
449+
&error,
450+
"Constraint creation",
451+
PluginType::MySQL,
452+
Some(self.instance.get_database().as_str()),
453+
)
454+
.await;
455+
}
456+
}
457+
let _: Result<(), DbErr> = connection.close().await;
458+
Ok(())
459+
}
410460
}
411461

412462
impl DatabaseAutoCreation for MySqlAutoCreation {
@@ -460,36 +510,33 @@ impl DatabaseAutoCreation for MySqlAutoCreation {
460510
.await;
461511
}
462512
}
463-
for index_sql in schema.get_indexes() {
464-
if let Err(error) = self.execute_sql(&connection, index_sql).await {
465-
AutoCreationLogger::log_auto_creation_error(
466-
&error,
467-
"Index creation",
468-
PluginType::MySQL,
469-
Some(self.instance.get_database().as_str()),
470-
)
471-
.await;
472-
}
473-
}
474-
for constraint_sql in schema.get_constraints() {
475-
if let Err(error) = self.execute_sql(&connection, constraint_sql).await {
513+
let _: Result<(), DbErr> = connection.close().await;
514+
AutoCreationLogger::log_tables_created(
515+
&created_tables,
516+
self.instance.get_database().as_str(),
517+
PluginType::MySQL,
518+
)
519+
.await;
520+
Ok(created_tables)
521+
}
522+
523+
#[instrument_trace]
524+
async fn init_data(&self) -> Result<(), AutoCreationError> {
525+
let connection: DatabaseConnection = self.create_target_connection().await?;
526+
let schema: &DatabaseSchema = self.get_database_schema();
527+
for init_data_sql in schema.get_init_data() {
528+
if let Err(error) = self.execute_sql(&connection, init_data_sql).await {
476529
AutoCreationLogger::log_auto_creation_error(
477530
&error,
478-
"Constraint creation",
531+
"Init data insertion",
479532
PluginType::MySQL,
480533
Some(self.instance.get_database().as_str()),
481534
)
482535
.await;
483536
}
484537
}
485538
let _: Result<(), DbErr> = connection.close().await;
486-
AutoCreationLogger::log_tables_created(
487-
&created_tables,
488-
self.instance.get_database().as_str(),
489-
PluginType::MySQL,
490-
)
491-
.await;
492-
Ok(created_tables)
539+
Ok(())
493540
}
494541

495542
#[instrument_trace]

plugin/postgresql/impl.rs

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ impl DatabaseConnectionPlugin for PostgreSqlPlugin {
184184
result.get_mut_errors().push(error.to_string());
185185
}
186186
}
187+
if let Err(error) = auto_creator.create_indexes().await {
188+
AutoCreationLogger::log_auto_creation_error(
189+
&error,
190+
"Index creation",
191+
PluginType::PostgreSQL,
192+
Some(instance.get_database().as_str()),
193+
)
194+
.await;
195+
result.get_mut_errors().push(error.to_string());
196+
}
197+
if let Err(error) = auto_creator.init_data().await {
198+
AutoCreationLogger::log_auto_creation_error(
199+
&error,
200+
"Init data",
201+
PluginType::PostgreSQL,
202+
Some(instance.get_database().as_str()),
203+
)
204+
.await;
205+
result.get_mut_errors().push(error.to_string());
206+
}
187207
if let Err(error) = auto_creator.verify_connection().await {
188208
AutoCreationLogger::log_auto_creation_error(
189209
&error,
@@ -415,6 +435,36 @@ impl PostgreSqlAutoCreation {
415435
fn get_database_schema(&self) -> &DatabaseSchema {
416436
&self.schema
417437
}
438+
439+
#[instrument_trace]
440+
async fn create_indexes(&self) -> Result<(), AutoCreationError> {
441+
let connection: DatabaseConnection = self.create_target_connection().await?;
442+
let schema: &DatabaseSchema = self.get_database_schema();
443+
for index_sql in schema.get_indexes() {
444+
if let Err(error) = self.execute_sql(&connection, index_sql).await {
445+
AutoCreationLogger::log_auto_creation_error(
446+
&error,
447+
"Index creation",
448+
PluginType::PostgreSQL,
449+
Some(self.instance.get_database().as_str()),
450+
)
451+
.await;
452+
}
453+
}
454+
for constraint_sql in schema.get_constraints() {
455+
if let Err(error) = self.execute_sql(&connection, constraint_sql).await {
456+
AutoCreationLogger::log_auto_creation_error(
457+
&error,
458+
"Constraint creation",
459+
PluginType::PostgreSQL,
460+
Some(self.instance.get_database().as_str()),
461+
)
462+
.await;
463+
}
464+
}
465+
let _: Result<(), DbErr> = connection.close().await;
466+
Ok(())
467+
}
418468
}
419469

420470
impl DatabaseAutoCreation for PostgreSqlAutoCreation {
@@ -468,36 +518,33 @@ impl DatabaseAutoCreation for PostgreSqlAutoCreation {
468518
.await;
469519
}
470520
}
471-
for index_sql in schema.get_indexes() {
472-
if let Err(error) = self.execute_sql(&connection, index_sql).await {
473-
AutoCreationLogger::log_auto_creation_error(
474-
&error,
475-
"Index creation",
476-
PluginType::PostgreSQL,
477-
Some(self.instance.get_database().as_str()),
478-
)
479-
.await;
480-
}
481-
}
482-
for constraint_sql in schema.get_constraints() {
483-
if let Err(error) = self.execute_sql(&connection, constraint_sql).await {
521+
let _: Result<(), DbErr> = connection.close().await;
522+
AutoCreationLogger::log_tables_created(
523+
&created_tables,
524+
self.instance.get_database().as_str(),
525+
PluginType::PostgreSQL,
526+
)
527+
.await;
528+
Ok(created_tables)
529+
}
530+
531+
#[instrument_trace]
532+
async fn init_data(&self) -> Result<(), AutoCreationError> {
533+
let connection: DatabaseConnection = self.create_target_connection().await?;
534+
let schema: &DatabaseSchema = self.get_database_schema();
535+
for init_data_sql in schema.get_init_data() {
536+
if let Err(error) = self.execute_sql(&connection, init_data_sql).await {
484537
AutoCreationLogger::log_auto_creation_error(
485538
&error,
486-
"Constraint creation",
539+
"Init data insertion",
487540
PluginType::PostgreSQL,
488541
Some(self.instance.get_database().as_str()),
489542
)
490543
.await;
491544
}
492545
}
493546
let _: Result<(), DbErr> = connection.close().await;
494-
AutoCreationLogger::log_tables_created(
495-
&created_tables,
496-
self.instance.get_database().as_str(),
497-
PluginType::PostgreSQL,
498-
)
499-
.await;
500-
Ok(created_tables)
547+
Ok(())
501548
}
502549

503550
#[instrument_trace]

plugin/redis/impl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@ impl DatabaseAutoCreation for RedisAutoCreation {
443443
Ok(setup_operations)
444444
}
445445

446+
#[instrument_trace]
447+
async fn init_data(&self) -> Result<(), AutoCreationError> {
448+
Ok(())
449+
}
450+
446451
#[instrument_trace]
447452
async fn verify_connection(&self) -> Result<(), AutoCreationError> {
448453
match self.validate_redis_server().await {

0 commit comments

Comments
 (0)