Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions designate/db/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions designate/db/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: ZoneCount :one
SELECT COUNT(*) FROM zones;
21 changes: 21 additions & 0 deletions designate/db/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions schema/designate/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE
`zones` (
`id` varchar(36) NOT NULL,
`version` int NOT NULL DEFAULT '1',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted` char(32) NOT NULL DEFAULT '0',
`deleted_at` datetime DEFAULT NULL,
`shard` smallint NOT NULL,
`tenant_id` varchar(36) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`description` varchar(160) DEFAULT NULL,
`type` enum('PRIMARY','SECONDARY','CATALOG') NOT NULL,
`transferred_at` datetime DEFAULT NULL,
`ttl` int NOT NULL,
`serial` int NOT NULL,
`refresh` int NOT NULL,
`retry` int NOT NULL,
`expire` int NOT NULL,
`minimum` int NOT NULL,
`status` enum('ACTIVE','PENDING','DELETED','ERROR') NOT NULL DEFAULT 'PENDING',
`parent_zone_id` varchar(36) DEFAULT NULL,
`action` enum('CREATE','DELETE','UPDATE','NONE') NOT NULL DEFAULT 'CREATE',
`pool_id` varchar(36) DEFAULT NULL,
`reverse_name` varchar(255) NOT NULL,
`delayed_notify` tinyint(1) NOT NULL DEFAULT '0',
`increment_serial` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_zone_name` (`name`, `deleted`, `pool_id`)
);
8 changes: 8 additions & 0 deletions sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ sql:
package: glance
out: glance/db
emit_exported_queries: true
- engine: mysql
schema: schema/designate/schema.sql
queries: designate/db/queries.sql
gen:
go:
package: designate
out: designate/db
emit_exported_queries: true
- engine: mysql
schema: schema/keystone/schema.sql
queries: keystone/db/queries.sql
Expand Down
19 changes: 19 additions & 0 deletions tests/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"github.com/stretchr/testify/require"
cinder "github.com/vexxhost/openstackdb/cinder/db"
designate "github.com/vexxhost/openstackdb/designate/db"
glance "github.com/vexxhost/openstackdb/glance/db"
heat "github.com/vexxhost/openstackdb/heat/db"
"github.com/vexxhost/openstackdb/internal/testutil"
Expand Down Expand Up @@ -99,6 +100,24 @@ func TestGlanceQueries(t *testing.T) {
_, err = q.ImageGetAll(ctx)
require.NoError(t, err, "ImageGetAll")
}
func TestDesignateQueries(t *testing.T) {
ctx := context.Background()
conn := testutil.NewMySQLContainer(t, "designate", "../sql/designate/schema.sql")
q := designate.New(conn)
count, err := q.ZoneCount(ctx)
require.NoError(t, err, "ZoneCount")
require.Zero(t, count)
testutil.SeedSQL(t, conn, `INSERT INTO zones (
id, shard, tenant_id, name, email, type, ttl, serial, refresh, retry,
expire, minimum, status, action, reverse_name
) VALUES (
'zone-1', 0, 'tenant-1', 'example.org.', 'admin@example.org', 'PRIMARY',
3600, 1, 3600, 600, 86400, 3600, 'ACTIVE', 'NONE', 'org.example.'
)`)
count, err = q.ZoneCount(ctx)
require.NoError(t, err, "ZoneCount")
require.EqualValues(t, 1, count)
}
func TestKeystoneQueries(t *testing.T) {
ctx := context.Background()
conn := testutil.NewMySQLContainer(t, "keystone", "../sql/keystone/schema.sql")
Expand Down
Loading