Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: use lower case, kebab-case for phrases in API to be consistent with the frontend (#1002)

tianzhou69da7656616e
diff --git a/docs/api-style-guide.md b/docs/api-style-guide.md
index b75e162779..75db84935a 100644
--- a/docs/api-style-guide.md
+++ b/docs/api-style-guide.md
@@ -16,13 +16,11 @@ Most of the time, we only want to do partial update on the resource, and we shou
Bytebase uses auto incremental ID as the primary key for all resources. To address a particular resource, we use GET `/issue/42`, if we want to support other addressing mechanism like using resource name, we should use query parameter like `.issue/42?name=foo`
-## Use lower case and do not use separator to split the words
+## Use lower case, kebab-case for phrases
-Use `/foo/barbaz` instead of `/foo/barBaz` or `/foo/bar-baz`
+Use `/foo/bar-baz` instead of `/foo/barBaz` or `/foo/barbaz`
-_Rationale_: The rule is simple and thus improve consistency. e.g. Say we have a resource called `datasource`, both `data source` and `datasource` are acceptable terms, under our rule, it's always `datasource`. This does hurt readability sometimes, but most of the time, we should only have at most 2 words inside a path component of the URL and our brain is pretty good at recognizing the individual word.
-
-_Note_: It's more common to use camelCase or dash-case. However, we are not alone, [Kubernetes](https://kubernetes.io/docs/reference/) also adopts this convention.
+_Rationale_: To be consistent with [the URL naming from the frontend guide](https://github.com/bytebase/bytebase/blob/main/docs/fe-style-guide.md#use-lower-case-kebab-case-for-phrases). Note, we once used `/foo/barbaz` style and it has its own merits. But because it's a better option to use keba-case in the frontend URL, and to avoid brain split, we make backend API to conform the same style as well.
## Use singular form even for collection resource
diff --git a/frontend/src/components/DataSourceTable.vue b/frontend/src/components/DataSourceTable.vue
index 8daf895ded..ec226e0e46 100644
--- a/frontend/src/components/DataSourceTable.vue
+++ b/frontend/src/components/DataSourceTable.vue
@@ -220,7 +220,7 @@ export default {
router.push(
`/db/${databaseSlug(
dataSource.database
- )}/datasource/${dataSourceSlug(dataSource)}`
+ )}/data-source/${dataSourceSlug(dataSource)}`
);
});
};
@@ -228,7 +228,7 @@ export default {
const clickDataSource = function (section: number, row: number) {
const dataSource = dataSourceSectionList.value[section].list![row];
router.push(
- `/db/${databaseSlug(dataSource.database)}/datasource/${dataSourceSlug(
+ `/db/${databaseSlug(dataSource.database)}/data-source/${dataSourceSlug(
dataSource
)}`
);
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index 9711e93e80..b173202c0c 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -128,7 +128,7 @@
</div>
<div class="relative flex justify-start">
<router-link
- :to="`/db/${databaseSlug}/datasource/${dataSourceSlug(ds)}`"
+ :to="`/db/${databaseSlug}/data-source/${dataSourceSlug(ds)}`"
class="pr-3 bg-white font-medium normal-link"
>{{ ds.name }}</router-link
>
diff --git a/frontend/src/store/modules/backup.ts b/frontend/src/store/modules/backup.ts
index bcf9bd8a7d..9038e977ce 100644
--- a/frontend/src/store/modules/backup.ts
+++ b/frontend/src/store/modules/backup.ts
@@ -128,7 +128,7 @@ const actions = {
{ commit, rootGetters }: any,
databaseId: DatabaseId
) {
- const data = (await axios.get(`/api/database/${databaseId}/backupsetting`))
+ const data = (await axios.get(`/api/database/${databaseId}/backup-setting`))
.data;
const backupSetting: BackupSetting = convertBackupSetting(
data.data,
@@ -146,7 +146,7 @@ const actions = {
) {
const data = (
await axios.patch(
- `/api/database/${newBackupSetting.databaseId}/backupsetting`,
+ `/api/database/${newBackupSetting.databaseId}/backup-setting`,
{
data: {
type: "BackupSettingUpsert",
diff --git a/frontend/src/store/modules/dataSource.ts b/frontend/src/store/modules/dataSource.ts
index 7df81e3077..8a5246d255 100644
--- a/frontend/src/store/modules/dataSource.ts
+++ b/frontend/src/store/modules/dataSource.ts
@@ -77,7 +77,7 @@ const actions = {
}: { dataSourceId: DataSourceId; databaseId: DatabaseId }
) {
const data = (
- await axios.get(`/api/database/${databaseId}/datasource/${dataSourceId}`)
+ await axios.get(`/api/database/${databaseId}/data-source/${dataSourceId}`)
).data;
const dataSource = convert(data.data, data.included, rootGetters);
@@ -94,7 +94,7 @@ const actions = {
newDataSource: DataSourceCreate
) {
const data = (
- await axios.post(`/api/database/${newDataSource.databaseId}/datasource`, {
+ await axios.post(`/api/database/${newDataSource.databaseId}/data-source`, {
data: {
type: "DataSourceCreate",
attributes: newDataSource,
@@ -125,7 +125,7 @@ const actions = {
) {
const data = (
await axios.patch(
- `/api/database/${databaseId}/datasource/${dataSourceId}`,
+ `/api/database/${databaseId}/data-source/${dataSourceId}`,
{
data: {
type: "dataSourcePatch",
@@ -152,7 +152,7 @@ const actions = {
}: { databaseId: DatabaseId; dataSourceId: DataSourceId }
) {
await axios.delete(
- `/api/database/${databaseId}/datasource/${dataSourceId}`
+ `/api/database/${databaseId}/data-source/${dataSourceId}`
);
commit("deleteDataSourceById", dataSourceId);
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index 018c9773ba..8f084ae23f 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -276,7 +276,7 @@ const actions = {
{ dispatch }: any,
{ projectId }: { projectId: ProjectId }
) {
- await axios.post(`/api/project/${projectId}/syncmember`);
+ await axios.post(`/api/project/${projectId}/sync-member`);
const updatedProject = await dispatch("fetchProjectById", projectId);
return updatedProject;
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index 07a3bf2f62..bb7c2ab6e5 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -96,10 +96,10 @@ const getters = {
}
{
- // /db/:databaseSlug/datasource/:dataSourceSlug
+ // /db/:databaseSlug/data-source/:dataSourceSlug
// Total 3 elements, 2nd element is the database slug, 3rd element is the data source slug
const dataSourceComponents = currentRoute.path.match(
- "/db/([0-9a-zA-Z_-]+)/datasource/([0-9a-zA-Z_-]+)"
+ "/db/([0-9a-zA-Z_-]+)/data-source/([0-9a-zA-Z_-]+)"
) || ["/", undefined, undefined];
if (dataSourceComponents[1] && dataSourceComponents[2]) {
return {
diff --git a/frontend/src/store/modules/sql.ts b/frontend/src/store/modules/sql.ts
index 41dbb36278..2f9795542f 100644
--- a/frontend/src/store/modules/sql.ts
+++ b/frontend/src/store/modules/sql.ts
@@ -39,7 +39,7 @@ const actions = {
async syncSchema({ dispatch }: any, instanceId: InstanceId) {
const data = (
await axios.post(
- `/api/sql/syncschema`,
+ `/api/sql/sync-schema`,
{
data: {
type: "sqlSyncSchema",
diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.ts
index ec2805bd56..30ea14ba0b 100644
--- a/frontend/src/utils/slug.ts
+++ b/frontend/src/utils/slug.ts
@@ -75,7 +75,7 @@ export function fullDatabasePath(database: Database): string {
}
export function fullDataSourcePath(dataSource: DataSource): string {
- return `/db/${databaseSlug(dataSource.database)}/datasource/${dataSourceSlug(
+ return `/db/${databaseSlug(dataSource.database)}/data-source/${dataSourceSlug(
dataSource
)}`;
}
diff --git a/server/acl_casbin_policy_dba.csv b/server/acl_casbin_policy_dba.csv
index f83de307ea..032ab4b433 100644
--- a/server/acl_casbin_policy_dba.csv
+++ b/server/acl_casbin_policy_dba.csv
@@ -12,7 +12,7 @@ p, DBA, /project/{id}/repository, PATCH
p, DBA, /project/{id}/repository, DELETE
p, DBA, /project/{id}/deployment, GET
p, DBA, /project/{id}/deployment, PATCH
-p, DBA, /project/{projectID}/syncmember, POST
+p, DBA, /project/{projectID}/sync-member, POST
p, DBA, /project/{projectID}/member, POST
p, DBA, /project/{projectID}/member/{memberID}, PATCH
p, DBA, /project/{projectID}/member/{memberID}, DELETE
@@ -45,11 +45,11 @@ p, DBA, /database/{id}/table/{tableName}, GET
p, DBA, /database/{id}/view, GET
p, DBA, /database/{id}/backup, GET
p, DBA, /database/{id}/backup, POST
-p, DBA, /database/{id}/backupsetting, GET
-p, DBA, /database/{id}/backupsetting, PATCH
-p, DBA, /database/{id}/datasource, POST
-p, DBA, /database/{id}/datasource/{dataSourceID}, GET
-p, DBA, /database/{id}/datasource/{dataSourceID}, PATCH
+p, DBA, /database/{id}/backup-setting, GET
+p, DBA, /database/{id}/backup-setting, PATCH
+p, DBA, /database/{id}/data-source, POST
+p, DBA, /database/{id}/data-source/{dataSourceID}, GET
+p, DBA, /database/{id}/data-source/{dataSourceID}, PATCH
p, DBA, /issue, POST
p, DBA, /issue, GET
p, DBA, /issue/{id}, GET
@@ -72,7 +72,7 @@ p, DBA, /pipeline/{pipelineID}/task/{taskID}, PATCH
p, DBA, /pipeline/{pipelineID}/task/{taskID}/status, PATCH
p, DBA, /pipeline/{pipelineID}/task/{taskID}/check, POST
p, DBA, /sql/ping, POST
-p, DBA, /sql/syncschema, POST
+p, DBA, /sql/sync-schema, POST
p, DBA, /sql/execute, POST
p, DBA, /vcs, POST
p, DBA, /vcs, GET
diff --git a/server/acl_casbin_policy_developer.csv b/server/acl_casbin_policy_developer.csv
index a35ed041ad..2091a09928 100644
--- a/server/acl_casbin_policy_developer.csv
+++ b/server/acl_casbin_policy_developer.csv
@@ -12,7 +12,7 @@ p, DEVELOPER, /project/{id}/repository, PATCH
p, DEVELOPER, /project/{id}/repository, DELETE
p, DEVELOPER, /project/{id}/deployment, GET
p, DEVELOPER, /project/{id}/deployment, PATCH
-p, DEVELOPER, /project/{projectID}/syncmember, POST
+p, DEVELOPER, /project/{projectID}/sync-member, POST
p, DEVELOPER, /project/{projectID}/member, POST
p, DEVELOPER, /project/{projectID}/member/{memberID}, PATCH
p, DEVELOPER, /project/{projectID}/member/{memberID}, DELETE
@@ -40,11 +40,11 @@ p, DEVELOPER, /database/{id}/table/{tableName}, GET
p, DEVELOPER, /database/{id}/view, GET
p, DEVELOPER, /database/{id}/backup, GET
p, DEVELOPER, /database/{id}/backup, POST
-p, DEVELOPER, /database/{id}/backupsetting, GET
-p, DEVELOPER, /database/{id}/backupsetting, PATCH
-p, DEVELOPER, /database/{id}/datasource, POST
-p, DEVELOPER, /database/{id}/datasource/{dataSourceID}, GET
-p, DEVELOPER, /database/{id}/datasource/{dataSourceID}, PATCH
+p, DEVELOPER, /database/{id}/backup-setting, GET
+p, DEVELOPER, /database/{id}/backup-setting, PATCH
+p, DEVELOPER, /database/{id}/data-source, POST
+p, DEVELOPER, /database/{id}/data-source/{dataSourceID}, GET
+p, DEVELOPER, /database/{id}/data-source/{dataSourceID}, PATCH
p, DEVELOPER, /issue, POST
p, DEVELOPER, /issue, GET
p, DEVELOPER, /issue/{id}, GET
diff --git a/server/acl_casbin_policy_owner.csv b/server/acl_casbin_policy_owner.csv
index 5280812da2..460914e30b 100644
--- a/server/acl_casbin_policy_owner.csv
+++ b/server/acl_casbin_policy_owner.csv
@@ -16,7 +16,7 @@ p, OWNER, /project/{id}/repository, PATCH
p, OWNER, /project/{id}/repository, DELETE
p, OWNER, /project/{id}/deployment, GET
p, OWNER, /project/{id}/deployment, PATCH
-p, OWNER, /project/{projectID}/syncmember, POST
+p, OWNER, /project/{projectID}/sync-member, POST
p, OWNER, /project/{projectID}/member, POST
p, OWNER, /project/{projectID}/member/{memberID}, PATCH
p, OWNER, /project/{projectID}/member/{memberID}, DELETE
@@ -49,11 +49,11 @@ p, OWNER, /database/{id}/table/{tableName}, GET
p, OWNER, /database/{id}/view, GET
p, OWNER, /database/{id}/backup, GET
p, OWNER, /database/{id}/backup, POST
-p, OWNER, /database/{id}/backupsetting, GET
-p, OWNER, /database/{id}/backupsetting, PATCH
-p, OWNER, /database/{id}/datasource, POST
-p, OWNER, /database/{id}/datasource/{dataSourceID}, GET
-p, OWNER, /database/{id}/datasource/{dataSourceID}, PATCH
+p, OWNER, /database/{id}/backup-setting, GET
+p, OWNER, /database/{id}/backup-setting, PATCH
+p, OWNER, /database/{id}/data-source, POST
+p, OWNER, /database/{id}/data-source/{dataSourceID}, GET
+p, OWNER, /database/{id}/data-source/{dataSourceID}, PATCH
p, OWNER, /issue, POST
p, OWNER, /issue, GET
p, OWNER, /issue/{id}, GET
@@ -76,7 +76,7 @@ p, OWNER, /pipeline/{pipelineID}/task/{taskID}, PATCH
p, OWNER, /pipeline/{pipelineID}/task/{taskID}/status, PATCH
p, OWNER, /pipeline/{pipelineID}/task/{taskID}/check, POST
p, OWNER, /sql/ping, POST
-p, OWNER, /sql/syncschema, POST
+p, OWNER, /sql/sync-schema, POST
p, OWNER, /sql/execute, POST
p, OWNER, /vcs, POST
p, OWNER, /vcs, GET
diff --git a/server/database.go b/server/database.go
index 1bfd24b673..baf449c4bc 100644
--- a/server/database.go
+++ b/server/database.go
@@ -674,7 +674,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
return nil
})
- g.PATCH("/database/:id/backupsetting", func(c echo.Context) error {
+ g.PATCH("/database/:id/backup-setting", func(c echo.Context) error {
ctx := context.Background()
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
@@ -711,7 +711,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
return nil
})
- g.GET("/database/:id/backupsetting", func(c echo.Context) error {
+ g.GET("/database/:id/backup-setting", func(c echo.Context) error {
ctx := context.Background()
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
@@ -752,7 +752,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
return nil
})
- g.GET("/database/:id/datasource/:dataSourceID", func(c echo.Context) error {
+ g.GET("/database/:id/data-source/:dataSourceID", func(c echo.Context) error {
ctx := context.Background()
databaseID, err := strconv.Atoi(c.Param("id"))
if err != nil {
@@ -796,7 +796,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
return nil
})
- g.POST("/database/:id/datasource", func(c echo.Context) error {
+ g.POST("/database/:id/data-source", func(c echo.Context) error {
ctx := context.Background()
databaseID, err := strconv.Atoi(c.Param("id"))
if err != nil {
@@ -834,7 +834,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
return nil
})
- g.PATCH("/database/:id/datasource/:dataSourceID", func(c echo.Context) error {
+ g.PATCH("/database/:id/data-source/:dataSourceID", func(c echo.Context) error {
ctx := context.Background()
databaseID, err := strconv.Atoi(c.Param("id"))
if err != nil {
diff --git a/server/project_member.go b/server/project_member.go
index ca409ccfc1..0281084dd3 100644
--- a/server/project_member.go
+++ b/server/project_member.go
@@ -18,7 +18,7 @@ import (
func (s *Server) registerProjectMemberRoutes(g *echo.Group) {
// for now we only support sync project member from privately deployed GitLab
- g.POST("/project/:projectID/syncmember", func(c echo.Context) error {
+ g.POST("/project/:projectID/sync-member", func(c echo.Context) error {
ctx := context.Background()
projectID, err := strconv.Atoi(c.Param("projectID"))
if err != nil {
diff --git a/server/sql.go b/server/sql.go
index 2fd56022c7..36b4f82db2 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -75,7 +75,7 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {
return nil
})
- g.POST("/sql/syncschema", func(c echo.Context) error {
+ g.POST("/sql/sync-schema", func(c echo.Context) error {
ctx := context.Background()
sync := &api.SQLSyncSchema{}
if err := jsonapi.UnmarshalPayload(c.Request().Body, sync); err != nil {
diff --git a/tests/schema_update_test.go b/tests/schema_update_test.go
index a101d3366f..315edc38fc 100644
--- a/tests/schema_update_test.go
+++ b/tests/schema_update_test.go
@@ -262,7 +262,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
_, err = ctl.listSheets(database.ID)
require.NoError(t, err)
- // Test if POST /api/database/:id/datasource api is working right.
+ // Test if POST /api/database/:id/data-source api is working right.
// TODO(steven): I will add read-only data source testing to a separate test later.
err = ctl.createDataSource(api.DataSourceCreate{
InstanceID: instance.ID,
diff --git a/tests/tests.go b/tests/tests.go
index 0a8acb37e2..9fd219028b 100644
--- a/tests/tests.go
+++ b/tests/tests.go
@@ -1107,7 +1107,7 @@ func (ctl *controller) createDataSource(dataSourceCreate api.DataSourceCreate) e
return fmt.Errorf("failed to marshal dataSourceCreate, error: %w", err)
}
- body, err := ctl.post(fmt.Sprintf("/database/%d/datasource", dataSourceCreate.DatabaseID), buf)
+ body, err := ctl.post(fmt.Sprintf("/database/%d/data-source", dataSourceCreate.DatabaseID), buf)
if err != nil {
return err
}