diff --git a/internal/dbtest/query_test.go b/internal/dbtest/query_test.go index ec5315a23..abb1322d5 100644 --- a/internal/dbtest/query_test.go +++ b/internal/dbtest/query_test.go @@ -628,6 +628,12 @@ func TestQuery(t *testing.T) { ColumnExpr(`email VARCHAR`). ColumnExpr(`password VARCHAR`) }, + func(db *bun.DB) schema.QueryAppender { + return db.NewCreateTable().Model(new(Model)).PartitionBy("HASH (id)") + }, + func(db *bun.DB) schema.QueryAppender { + return db.NewCreateTable().Model(new(Model)).TableSpace("fasttablespace") + }, } timeRE := regexp.MustCompile(`'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+(\+\d{2}:\d{2})?'`) diff --git a/internal/dbtest/testdata/snapshots/TestQuery-mysql5-102 b/internal/dbtest/testdata/snapshots/TestQuery-mysql5-102 new file mode 100644 index 000000000..8d591a8d8 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-mysql5-102 @@ -0,0 +1 @@ +CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) PARTITION BY HASH (id) diff --git a/internal/dbtest/testdata/snapshots/TestQuery-mysql5-103 b/internal/dbtest/testdata/snapshots/TestQuery-mysql5-103 new file mode 100644 index 000000000..74eba5720 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-mysql5-103 @@ -0,0 +1 @@ +CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) TABLESPACE `fasttablespace` diff --git a/internal/dbtest/testdata/snapshots/TestQuery-mysql8-102 b/internal/dbtest/testdata/snapshots/TestQuery-mysql8-102 new file mode 100644 index 000000000..8d591a8d8 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-mysql8-102 @@ -0,0 +1 @@ +CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) PARTITION BY HASH (id) diff --git a/internal/dbtest/testdata/snapshots/TestQuery-mysql8-103 b/internal/dbtest/testdata/snapshots/TestQuery-mysql8-103 new file mode 100644 index 000000000..74eba5720 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-mysql8-103 @@ -0,0 +1 @@ +CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) TABLESPACE `fasttablespace` diff --git a/internal/dbtest/testdata/snapshots/TestQuery-pg-102 b/internal/dbtest/testdata/snapshots/TestQuery-pg-102 new file mode 100644 index 000000000..c73aab695 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-pg-102 @@ -0,0 +1 @@ +CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) PARTITION BY HASH (id) diff --git a/internal/dbtest/testdata/snapshots/TestQuery-pg-103 b/internal/dbtest/testdata/snapshots/TestQuery-pg-103 new file mode 100644 index 000000000..0f8e8d975 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-pg-103 @@ -0,0 +1 @@ +CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) TABLESPACE "fasttablespace" diff --git a/internal/dbtest/testdata/snapshots/TestQuery-pgx-102 b/internal/dbtest/testdata/snapshots/TestQuery-pgx-102 new file mode 100644 index 000000000..c73aab695 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-pgx-102 @@ -0,0 +1 @@ +CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) PARTITION BY HASH (id) diff --git a/internal/dbtest/testdata/snapshots/TestQuery-pgx-103 b/internal/dbtest/testdata/snapshots/TestQuery-pgx-103 new file mode 100644 index 000000000..0f8e8d975 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-pgx-103 @@ -0,0 +1 @@ +CREATE TABLE "models" ("id" BIGSERIAL NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) TABLESPACE "fasttablespace" diff --git a/internal/dbtest/testdata/snapshots/TestQuery-sqlite-102 b/internal/dbtest/testdata/snapshots/TestQuery-sqlite-102 new file mode 100644 index 000000000..5083c3448 --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-sqlite-102 @@ -0,0 +1 @@ +CREATE TABLE "models" ("id" INTEGER NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) PARTITION BY HASH (id) diff --git a/internal/dbtest/testdata/snapshots/TestQuery-sqlite-103 b/internal/dbtest/testdata/snapshots/TestQuery-sqlite-103 new file mode 100644 index 000000000..45b5197cc --- /dev/null +++ b/internal/dbtest/testdata/snapshots/TestQuery-sqlite-103 @@ -0,0 +1 @@ +CREATE TABLE "models" ("id" INTEGER NOT NULL, "str" VARCHAR, PRIMARY KEY ("id")) TABLESPACE "fasttablespace" diff --git a/query_table_create.go b/query_table_create.go index 9d4fda104..66bb9c4a1 100644 --- a/query_table_create.go +++ b/query_table_create.go @@ -90,6 +90,18 @@ func (q *CreateTableQuery) ForeignKey(query string, args ...interface{}) *Create return q } +func (q *CreateTableQuery) PartitionBy(query string, args ...interface{}) *CreateTableQuery { + q.partitionBy = schema.SafeQuery(query, args) + return q +} + +func (q *CreateTableQuery) TableSpace(tablespace string) *CreateTableQuery { + q.tablespace = schema.UnsafeIdent(tablespace) + return q +} + +//------------------------------------------------------------------------------ + func (q *CreateTableQuery) Operation() string { return "CREATE TABLE" }