Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(filer): use DROP TABLE IF EXISTS in SQL stores (#10158)

Chris Lu803c5a8dcae0
diff --git a/weed/filer/mysql/mysql_store.go b/weed/filer/mysql/mysql_store.go
index 3513b55239..abcef6fe6e 100644
--- a/weed/filer/mysql/mysql_store.go
+++ b/weed/filer/mysql/mysql_store.go
@@ -72,7 +72,7 @@ func (store *MysqlStore) initialize(dsn string, upsertQuery string, enableUpsert
}
gen := &SqlGenMysql{
CreateTableSqlTemplate: "",
- DropTableSqlTemplate: "DROP TABLE `%s`",
+ DropTableSqlTemplate: "DROP TABLE IF EXISTS `%s`",
UpsertQueryTemplate: upsertQuery,
}
store.SqlGenerator = gen
diff --git a/weed/filer/mysql2/mysql2_store.go b/weed/filer/mysql2/mysql2_store.go
index b4845ec074..0ff58f2aca 100644
--- a/weed/filer/mysql2/mysql2_store.go
+++ b/weed/filer/mysql2/mysql2_store.go
@@ -65,7 +65,7 @@ func (store *MysqlStore2) initialize(createTable, upsertQuery string, enableUpse
}
gen := &mysql.SqlGenMysql{
CreateTableSqlTemplate: createTable,
- DropTableSqlTemplate: "DROP TABLE `%s`",
+ DropTableSqlTemplate: "DROP TABLE IF EXISTS `%s`",
UpsertQueryTemplate: upsertQuery,
}
store.SqlGenerator = gen
diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go
index a2388624bb..c694f77c39 100644
--- a/weed/filer/postgres/postgres_store.go
+++ b/weed/filer/postgres/postgres_store.go
@@ -64,7 +64,7 @@ func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, us
}
gen := &SqlGenPostgres{
CreateTableSqlTemplate: "",
- DropTableSqlTemplate: `drop table "%s"`,
+ DropTableSqlTemplate: `drop table if exists "%s"`,
UpsertQueryTemplate: upsertQuery,
}
store.SqlGenerator = gen
diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go
index b818e550d1..3a08118af0 100644
--- a/weed/filer/postgres2/postgres2_store.go
+++ b/weed/filer/postgres2/postgres2_store.go
@@ -70,7 +70,7 @@ func (store *PostgresStore2) initialize(createTable, upsertQuery string, enableU
}
gen := &postgres.SqlGenPostgres{
CreateTableSqlTemplate: createTable,
- DropTableSqlTemplate: `drop table "%s"`,
+ DropTableSqlTemplate: `drop table if exists "%s"`,
UpsertQueryTemplate: upsertQuery,
}
store.SqlGenerator = gen
diff --git a/weed/filer/sqlite/sqlite_store.go b/weed/filer/sqlite/sqlite_store.go
index 5f04e64701..0e9fb73962 100644
--- a/weed/filer/sqlite/sqlite_store.go
+++ b/weed/filer/sqlite/sqlite_store.go
@@ -54,7 +54,7 @@ func (store *SqliteStore) initialize(dbFile, createTable, upsertQuery string) (e
store.SupportBucketTable = true
store.SqlGenerator = &mysql.SqlGenMysql{
CreateTableSqlTemplate: createTable,
- DropTableSqlTemplate: "drop table `%s`",
+ DropTableSqlTemplate: "drop table if exists `%s`",
UpsertQueryTemplate: upsertQuery,
}