Skip to content

Commit 0144c7f

Browse files
committed
delete old version before install new
1 parent b6e6280 commit 0144c7f

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

cli/src/commands/add.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,27 +223,35 @@ pub async fn add(
223223
}
224224
}
225225

226+
// Delete old extension
227+
migration_content.push_str("\n-- Delete existing extension if installed\n");
228+
migration_content.push_str(r#"drop extension if exists ""#);
229+
migration_content.push_str(&extension_name);
230+
migration_content.push('"');
231+
migration_content.push_str(";\n");
232+
226233
// Create the extension
227234
migration_content.push_str("-- Create the extension\n");
228235

229-
let schema = schema.as_ref().or(payload.metadata.schema.as_ref());
230-
migration_content.push_str(r#"create extension if not exists ""#);
236+
migration_content.push_str(r#"create extension ""#);
231237
migration_content.push_str(&extension_name);
232238
migration_content.push('"');
233239

234240
// add schema if specified
241+
let schema = schema.as_ref().or(payload.metadata.schema.as_ref());
235242
if let Some(schema) = schema {
236243
migration_content.push_str(r#" schema ""#);
237244
migration_content.push_str(schema);
238245
migration_content.push('"');
239246
}
240247

241248
// add version if specified
242-
if let Some(version) = version {
243-
migration_content.push_str(" version '");
244-
migration_content.push_str(version);
245-
migration_content.push('\'');
246-
}
249+
let version = version
250+
.as_ref()
251+
.unwrap_or(&payload.metadata.default_version);
252+
migration_content.push_str(" version '");
253+
migration_content.push_str(version);
254+
migration_content.push('\'');
247255

248256
migration_content.push_str(";\n");
249257

@@ -259,12 +267,7 @@ pub async fn add(
259267
migration_content.push_str("');\n");
260268

261269
// Write to file
262-
let mut filename = String::new();
263-
filename.push_str(&timestamp.to_string());
264-
filename.push('_');
265-
filename.push_str(&extension_name);
266-
filename.push_str("_install.sql");
267-
270+
let filename = format!("{timestamp}_{extension_name}_{version}_install.sql");
268271
let file_path = output_path.join(filename);
269272

270273
fs::write(&file_path, migration_content).await?;

0 commit comments

Comments
 (0)