Skip to content

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

Move Status (“ACTIVE” | “INVITED”) from principal to member table

天舟8028072b006f
diff --git a/api/member.go b/api/member.go
index 86f2df63a3..e69ea890bc 100644
--- a/api/member.go
+++ b/api/member.go
@@ -5,6 +5,26 @@ import (
"encoding/json"
)
+type MemberStatus string
+
+const (
+ Unknown MemberStatus = "UNKNOWN"
+ Invited MemberStatus = "INVITED"
+ Active MemberStatus = "ACTIVE"
+)
+
+func (e MemberStatus) String() string {
+ switch e {
+ case Unknown:
+ return "UNKNOWN"
+ case Invited:
+ return "INVITED"
+ case Active:
+ return "ACTIVE"
+ }
+ return ""
+}
+
type Role string
const (
@@ -37,7 +57,8 @@ type Member struct {
UpdatedTs int64 `jsonapi:"attr,updatedTs"`
// Domain specific fields
- Role Role `jsonapi:"attr,role"`
+ Status MemberStatus `jsonapi:"attr,status"`
+ Role Role `jsonapi:"attr,role"`
PrincipalId int
Principal *Principal `jsonapi:"attr,principal"`
}
@@ -48,8 +69,9 @@ type MemberCreate struct {
CreatorId int
// Domain specific fields
- Role Role `jsonapi:"attr,role"`
- PrincipalId int `jsonapi:"attr,principalId"`
+ Status MemberStatus `jsonapi:"attr,status"`
+ Role Role `jsonapi:"attr,role"`
+ PrincipalId int `jsonapi:"attr,principalId"`
}
type MemberFind struct {
diff --git a/api/principal.go b/api/principal.go
index 8e638ef9f3..d9e2d8052b 100644
--- a/api/principal.go
+++ b/api/principal.go
@@ -7,26 +7,6 @@ import (
const SYSTEM_BOT_ID = 1
-type PrincipalStatus string
-
-const (
- Unknown PrincipalStatus = "UNKNOWN"
- Invited PrincipalStatus = "INVITED"
- Active PrincipalStatus = "ACTIVE"
-)
-
-func (e PrincipalStatus) String() string {
- switch e {
- case Unknown:
- return "UNKNOWN"
- case Invited:
- return "INVITED"
- case Active:
- return "ACTIVE"
- }
- return ""
-}
-
type PrincipalType string
const (
@@ -54,10 +34,9 @@ type Principal struct {
UpdatedTs int64 `jsonapi:"attr,updatedTs"`
// Domain specific fields
- Status PrincipalStatus `jsonapi:"attr,status"`
- Type PrincipalType `jsonapi:"attr,type"`
- Name string `jsonapi:"attr,name"`
- Email string `jsonapi:"attr,email"`
+ Type PrincipalType `jsonapi:"attr,type"`
+ Name string `jsonapi:"attr,name"`
+ Email string `jsonapi:"attr,email"`
// No need to return to the client
PasswordHash string
// Role is stored in the member table, but we include it when returning the principal.
@@ -69,23 +48,21 @@ type Principal struct {
// can map directly to the frontend Principal object without any conversion.
func (p *Principal) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
- ID int `json:"id"`
- CreatorId int `json:"creatorId"`
- CreatedTs int64 `json:"createdTs"`
- UpdaterId int `json:"updaterId"`
- UpdatedTs int64 `json:"updatedTs"`
- Status PrincipalStatus `json:"status"`
- Type PrincipalType `json:"type"`
- Name string `json:"name"`
- Email string `json:"email"`
- Role Role `json:"role"`
+ ID int `json:"id"`
+ CreatorId int `json:"creatorId"`
+ CreatedTs int64 `json:"createdTs"`
+ UpdaterId int `json:"updaterId"`
+ UpdatedTs int64 `json:"updatedTs"`
+ Type PrincipalType `json:"type"`
+ Name string `json:"name"`
+ Email string `json:"email"`
+ Role Role `json:"role"`
}{
ID: p.ID,
CreatorId: p.CreatorId,
CreatedTs: p.CreatedTs,
UpdaterId: p.UpdaterId,
UpdatedTs: p.UpdatedTs,
- Status: p.Status,
Type: p.Type,
Name: p.Name,
Email: p.Email,
@@ -100,7 +77,6 @@ type PrincipalCreate struct {
CreatorId int
// Domain specific fields
- Status PrincipalStatus `jsonapi:"attr,status"`
Type PrincipalType
Name string `jsonapi:"attr,name"`
Email string `jsonapi:"attr,email"`
diff --git a/frontend/src/components/MemberInvite.vue b/frontend/src/components/MemberAddOrInvite.vue
similarity index 64%
rename from frontend/src/components/MemberInvite.vue
rename to frontend/src/components/MemberAddOrInvite.vue
index abdf9e0c24..84a24154a0 100644
--- a/frontend/src/components/MemberInvite.vue
+++ b/frontend/src/components/MemberAddOrInvite.vue
@@ -2,25 +2,25 @@
<div class="space-y-4">
<div class="space-y-2">
<div
- v-for="(invite, index) in state.inviteList"
+ v-for="(user, index) in state.userList"
:key="index"
class="flex justify-between py-0.5 select-none"
>
- <p id="invite_members_helper" class="sr-only">
- Invite by email address
+ <p id="add_or_invite_members_helper" class="sr-only">
+ Add or invite by email address
</p>
<div class="flex flex-row space-x-4">
<div class="flex-grow">
<input
type="email"
- name="invite_members"
+ name="add_or_invite_members"
autocomplete="off"
class="w-36 sm:w-64 textfield lowercase"
placeholder="[email protected]"
- v-model="invite.email"
- @blur="validateInvite(invite, index)"
+ v-model="user.email"
+ @blur="validateUser(user, index)"
@input="clearValidationError(index)"
- aria-describedby="invite_members_helper"
+ aria-describedby="add_or_invite_members_helper"
/>
<p
v-if="state.errorList[index]"
@@ -32,10 +32,10 @@
</div>
<div v-if="hasAdminFeature" class="sm:hidden w-36">
<RoleSelect
- :selectedRole="invite.role"
+ :selectedRole="user.role"
@change-role="
(role) => {
- invite.role = role;
+ user.role = role;
}
"
/>
@@ -47,34 +47,34 @@
>
<div class="radio">
<input
- :name="`invite_role${index}`"
+ :name="`add_or_invite_role${index}`"
tabindex="-1"
type="radio"
class="btn"
value="OWNER"
- v-model="invite.role"
+ v-model="user.role"
/>
<label class="label"> Owner </label>
</div>
<div class="radio">
<input
- :name="`invite_role${index}`"
+ :name="`add_or_invite_role${index}`"
tabindex="-1"
type="radio"
class="btn"
value="DBA"
- v-model="invite.role"
+ v-model="user.role"
/>
<label class="label"> DBA </label>
</div>
<div class="radio">
<input
- :name="`invite_role${index}`"
+ :name="`add_or_invite_role${index}`"
tabindex="-1"
type="radio"
class="btn"
value="DEVELOPER"
- v-model="invite.role"
+ v-model="user.role"
/>
<label class="label"> Developer </label>
</div>
@@ -85,7 +85,7 @@
<div class="flex justify-between">
<span class="flex items-center">
- <button type="button" class="btn-secondary" @click.prevent="addInvite">
+ <button type="button" class="btn-secondary" @click.prevent="addUser">
+ Add More
</button>
</span>
@@ -93,10 +93,26 @@
<button
type="button"
class="btn-primary"
- :disabled="!hasValidInviteOnly()"
- @click.prevent="sendInvite"
+ :disabled="!hasValidUserOnly()"
+ @click.prevent="addOrInvite"
>
<svg
+ v-if="isAdd"
+ class="h-5 w-5"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M12 6v6m0 0v6m0-6h6m-6 0H6"
+ ></path>
+ </svg>
+ <svg
+ v-else
class="mr-2 h-5 w-5"
fill="none"
stroke="currentColor"
@@ -110,7 +126,7 @@
d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"
></path>
</svg>
- Send Invites
+ {{ isAdd ? "Add" : "Send Invites" }}
</button>
</div>
</div>
@@ -119,53 +135,65 @@
<script lang="ts">
import { computed, reactive } from "vue";
import { useStore } from "vuex";
-import RoleSelect from "../components/RoleSelect.vue";
-import { Principal, PrincipalCreate, MemberCreate, RoleType } from "../types";
-import { isValidEmail } from "../utils";
+import RoleSelect from "./RoleSelect.vue";
+import {
+ Principal,
+ PrincipalCreate,
+ MemberCreate,
+ RoleType,
+ UNKNOWN_ID,
+} from "../types";
+import { isOwner, isValidEmail } from "../utils";
-type Invite = {
+type User = {
email: string;
role: RoleType;
};
interface LocalState {
- inviteList: Invite[];
+ userList: User[];
errorList: string[];
}
export default {
- name: "MemberInvite",
+ name: "MemberAddOrInvite",
components: { RoleSelect },
props: {},
setup(props, ctx) {
const store = useStore();
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
+ const isAdd = computed(() => {
+ return isOwner(currentUser.value.role);
+ });
+
const hasAdminFeature = computed(() =>
store.getters["plan/feature"]("bb.admin")
);
const state = reactive<LocalState>({
- inviteList: [],
+ userList: [],
errorList: [],
});
for (let i = 0; i < 3; i++) {
- state.inviteList.push({
+ state.userList.push({
email: "",
role: "DEVELOPER",
});
state.errorList.push("");
}
- const validateInviteInternal = (invite: Invite): string => {
- if (invite.email) {
- if (!isValidEmail(invite.email)) {
+ const validateUserInternal = (user: User): string => {
+ if (user.email) {
+ if (!isValidEmail(user.email)) {
return "Invalid email address";
} else {
const principal = store.getters["principal/principalByEmail"](
- invite.email
+ user.email
);
- if (principal) {
+ if (principal.id != UNKNOWN_ID) {
return "Already a member";
}
}
@@ -173,8 +201,8 @@ export default {
return "";
};
- const validateInvite = (invite: Invite, index: number): boolean => {
- state.errorList[index] = validateInviteInternal(invite);
+ const validateUser = (user: User, index: number): boolean => {
+ state.errorList[index] = validateUserInternal(user);
return state.errorList[index].length == 0;
};
@@ -182,21 +210,21 @@ export default {
state.errorList[index] = "";
};
- const addInvite = () => {
- state.inviteList.push({
+ const addUser = () => {
+ state.userList.push({
email: "",
role: "DEVELOPER",
});
state.errorList.push("");
};
- const hasValidInviteOnly = () => {
+ const hasValidUserOnly = () => {
let hasEmailInput = false;
let hasError = false;
- state.inviteList.forEach((invite) => {
- if (invite.email) {
+ state.userList.forEach((user) => {
+ if (user.email) {
hasEmailInput = true;
- if (validateInviteInternal(invite).length > 0) {
+ if (validateUserInternal(user).length > 0) {
hasError = true;
return;
}
@@ -205,26 +233,29 @@ export default {
return !hasError && hasEmailInput;
};
- const sendInvite = () => {
- for (const invite of state.inviteList) {
- if (isValidEmail(invite.email)) {
- // If admin feature is NOT enabled, then we set every intite to OWNER role.
+ const addOrInvite = () => {
+ for (const user of state.userList) {
+ if (isValidEmail(user.email)) {
+ // Needs to assign to a local variable as user will change after createPrincipal but before createdMember
+ let role = user.role;
+ // If admin feature is NOT enabled, then we set every user to OWNER role.
if (!hasAdminFeature.value) {
- invite.role = "OWNER";
+ role = "OWNER";
}
// Note "principal/createPrincipal" would return the existing principal.
// This could happen if another client has just created the principal
// with this email.
const newPrincipal: PrincipalCreate = {
- name: invite.email.split("@")[0],
- email: invite.email,
+ name: user.email.split("@")[0],
+ email: user.email,
};
store
.dispatch("principal/createPrincipal", newPrincipal)
.then((principal: Principal) => {
const newMember: MemberCreate = {
principalId: principal.id,
- role: invite.role,
+ status: isAdd.value ? "ACTIVE" : "INVITED",
+ role,
};
// Note "principal/createdMember" would return the existing role mapping.
// This could happen if another client has just created the role mapping with
@@ -233,12 +264,12 @@ export default {
});
store.dispatch("uistate/saveIntroStateByKey", {
- key: "member.invite",
+ key: "member.addOrInvite",
newState: true,
});
}
}
- state.inviteList.forEach((item) => {
+ state.userList.forEach((item) => {
item.email = "";
item.role = "DEVELOPER";
});
@@ -247,12 +278,13 @@ export default {
return {
state,
+ isAdd,
hasAdminFeature,
- validateInvite,
+ validateUser,
clearValidationError,
- addInvite,
- hasValidInviteOnly,
- sendInvite,
+ addUser,
+ hasValidUserOnly,
+ addOrInvite,
};
},
};
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vue
index 25cf01afd9..2e115cc34d 100644
--- a/frontend/src/components/ProfileDropdown.vue
+++ b/frontend/src/components/ProfileDropdown.vue
@@ -133,7 +133,7 @@ export default {
newState: false,
});
store.dispatch("uistate/saveIntroStateByKey", {
- key: "member.invite",
+ key: "member.addOrInvite",
newState: false,
});
store.dispatch("uistate/saveIntroStateByKey", {
diff --git a/frontend/src/components/Quickstart.vue b/frontend/src/components/Quickstart.vue
index dff20a647f..34d1242a44 100644
--- a/frontend/src/components/Quickstart.vue
+++ b/frontend/src/components/Quickstart.vue
@@ -97,12 +97,13 @@
<script lang="ts">
import { computed, reactive, ComputedRef } from "vue";
import { useStore } from "vuex";
-import { isDBAOrOwner } from "../utils";
+import { isDBA, isDBAOrOwner, isOwner } from "../utils";
type IntroItem = {
name: string;
link: string;
- dbaAndOwnerOnly: boolean;
+ allowDBA: boolean;
+ allowDeveloper: Boolean;
done: ComputedRef<boolean>;
};
@@ -120,15 +121,26 @@ export default {
{
name: "Bookmark an issue",
link: "/issue/hello-world-1",
- dbaAndOwnerOnly: false,
+ allowDBA: true,
+ allowDeveloper: true,
done: computed(() => {
return store.getters["uistate/introStateByKey"]("bookmark.create");
}),
},
+ {
+ name: "Add a member",
+ link: "/setting/member",
+ allowDBA: false,
+ allowDeveloper: false,
+ done: computed(() =>
+ store.getters["uistate/introStateByKey"]("member.addOrInvite")
+ ),
+ },
{
name: "Add an environment",
link: "/environment",
- dbaAndOwnerOnly: true,
+ allowDBA: true,
+ allowDeveloper: false,
done: computed(() => {
return store.getters["uistate/introStateByKey"]("environment.create");
}),
@@ -136,7 +148,8 @@ export default {
{
name: "Add an instance",
link: "/instance",
- dbaAndOwnerOnly: true,
+ allowDBA: true,
+ allowDeveloper: false,
done: computed(() => {
return store.getters["uistate/introStateByKey"]("instance.create");
}),
@@ -144,7 +157,8 @@ export default {
{
name: "Create a project",
link: "/project",
- dbaAndOwnerOnly: false,
+ allowDBA: true,
+ allowDeveloper: true,
done: computed(() => {
return store.getters["uistate/introStateByKey"]("project.create");
}),
@@ -152,7 +166,8 @@ export default {
{
name: "Create a database",
link: "/db",
- dbaAndOwnerOnly: store.getters["plan/feature"]("bb.dba-workflow"),
+ allowDBA: true,
+ allowDeveloper: !store.getters["plan/feature"]("bb.dba-workflow"),
done: computed(() =>
store.getters["uistate/introStateByKey"]("database.create")
),
@@ -160,36 +175,31 @@ export default {
{
name: "Alter schema",
link: "/db",
- dbaAndOwnerOnly: false,
+ allowDBA: true,
+ allowDeveloper: true,
done: computed(() =>
store.getters["uistate/introStateByKey"]("schema.update")
),
},
- // {
- // name: "Invite a member",
- // link: "/setting/member",
- // dbaAndOwnerOnly: true,
- // done: computed(() =>
- // store.getters["uistate/introStateByKey"]("member.invite")
- // ),
- // },
]);
- const devIntroList: IntroItem[] = introList.filter(
- (item) => !item.dbaAndOwnerOnly
- );
-
const effectiveList = computed(() => {
- return isDBAOrOwner(currentUser.value.role) ? introList : devIntroList;
+ if (isOwner(currentUser.value.role)) {
+ return introList;
+ }
+ if (isDBA(currentUser.value.role)) {
+ return introList.filter((item) => item.allowDBA);
+ }
+ return introList.filter((item) => item.allowDeveloper);
});
const isTaskActive = (index: number): boolean => {
for (let i = index - 1; i >= 0; i--) {
- if (!introList[i].done) {
+ if (!effectiveList.value[i].done) {
return false;
}
}
- return !introList[index].done;
+ return !effectiveList.value[index].done;
};
const hideQuickstart = () => {
diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.ts
index 911f9b2224..33c6130614 100644
--- a/frontend/src/store/modules/principal.ts
+++ b/frontend/src/store/modules/principal.ts
@@ -5,7 +5,6 @@ import {
PrincipalCreate,
PrincipalPatch,
PrincipalState,
- PrincipalStatus,
ResourceObject,
unknown,
empty,
@@ -22,7 +21,6 @@ function convert(principal: ResourceObject): Principal {
createdTs: principal.attributes.createdTs as number,
updaterId: principal.attributes.updaterId as PrincipalId,
updatedTs: principal.attributes.updatedTs as number,
- status: principal.attributes.status as PrincipalStatus,
type: principal.attributes.type as PrincipalType,
name: principal.attributes.name as string,
email: principal.attributes.email as string,
@@ -99,10 +97,9 @@ const actions = {
data: {
type: "PrincipalCreate",
attributes: {
- status: "INVITED",
name: newPrincipal.name,
email: newPrincipal.email,
- password: isRelease() ? randomString() : "aaa",
+ password: randomString(),
},
},
})
diff --git a/frontend/src/types/member.ts b/frontend/src/types/member.ts
index f5baf5202e..1591cf7ddc 100644
--- a/frontend/src/types/member.ts
+++ b/frontend/src/types/member.ts
@@ -1,6 +1,8 @@
import { MemberId, PrincipalId } from "./id";
import { Principal } from "./principal";
+export type MemberStatus = "INVITED" | "ACTIVE";
+
export type RoleType = "OWNER" | "DBA" | "DEVELOPER";
export type Member = {
@@ -13,6 +15,7 @@ export type Member = {
updatedTs: number;
// Domain specific fields
+ status: MemberStatus;
role: RoleType;
principal: Principal;
};
@@ -20,6 +23,7 @@ export type Member = {
export type MemberCreate = {
// Domain specific fields
principalId: PrincipalId;
+ status: MemberStatus;
role: RoleType;
};
diff --git a/frontend/src/types/message.ts b/frontend/src/types/message.ts
index 46a42026f6..dffafeaf81 100644
--- a/frontend/src/types/message.ts
+++ b/frontend/src/types/message.ts
@@ -6,7 +6,7 @@ import { ProjectRoleType } from "./project";
export type MemberMessageType =
| "bb.message.member.create"
- | "bb.message.member.invite"
+ | "bb.message.member.add"
| "bb.message.member.join"
| "bb.message.member.revoke"
| "bb.message.member.updaterole";
diff --git a/frontend/src/types/principal.ts b/frontend/src/types/principal.ts
index 6aa4dd96bd..ba255a40d9 100644
--- a/frontend/src/types/principal.ts
+++ b/frontend/src/types/principal.ts
@@ -5,8 +5,6 @@ import { PrincipalId } from "./id";
import { RoleType } from "./member";
// we may support application/bot identity.
-export type PrincipalStatus = "INVITED" | "ACTIVE";
-
export type PrincipalType = "END_USER" | "SYSTEM_BOT";
export type Principal = {
@@ -21,7 +19,6 @@ export type Principal = {
updatedTs: number;
// Domain specific fields
- status: PrincipalStatus;
type: PrincipalType;
name: string;
email: string;
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index eb858cfc1c..8eac36a18a 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -67,7 +67,7 @@
<template
v-if="
message.type == 'bb.message.member.create' ||
- message.type == 'bb.message.member.invite' ||
+ message.type == 'bb.message.member.add' ||
message.type == 'bb.message.member.join' ||
message.type == 'bb.message.member.revoke' ||
message.type == 'bb.message.member.updaterole'
@@ -257,7 +257,7 @@ export default {
principalFromId(payload.principalId).email
} as ${roleName(payload.newRole!)}`;
}
- case "bb.message.member.invite": {
+ case "bb.message.member.add": {
const payload = message.payload as MemberMessagePayload;
return `invited ${
principalFromId(payload.principalId).email
diff --git a/frontend/src/views/SettingWorkspaceMember.vue b/frontend/src/views/SettingWorkspaceMember.vue
index ccb46f5b66..c0c0295476 100644
--- a/frontend/src/views/SettingWorkspaceMember.vue
+++ b/frontend/src/views/SettingWorkspaceMember.vue
@@ -1,6 +1,6 @@
<template>
- <div v-if="allowInvite" class="w-full flex justify-center mb-6">
- <MemberInvite />
+ <div v-if="allowAddOrInvite" class="w-full flex justify-center mb-6">
+ <MemberAddOrInvite />
</div>
<div>
<MemberTable />
@@ -9,21 +9,29 @@
<script lang="ts">
import { computed } from "vue";
-import MemberInvite from "../components/MemberInvite.vue";
+import { useStore } from "vuex";
+import MemberAddOrInvite from "../components/MemberAddOrInvite.vue";
import MemberTable from "../components/MemberTable.vue";
+import { isOwner } from "../utils";
export default {
name: "SettingWorkspaceMember",
- components: { MemberInvite, MemberTable },
+ components: { MemberAddOrInvite, MemberTable },
props: {},
setup(props, ctx) {
- // TODO: Disable invite for now as it requires mail server
- const allowInvite = computed(() => {
- return false;
+ const store = useStore();
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
+ const allowAddOrInvite = computed(() => {
+ // TODO: Enable for DBA and developer
+ // If current user is owner, MemberAddOrInvite is in Add mode.
+ // If current user is DBA or developer, MemberAddOrInvite is in Invite mode.
+ // For now, we only enable Add mode for owner
+ return isOwner(currentUser.value.role);
});
return {
- allowInvite,
+ allowAddOrInvite,
};
},
};
diff --git a/server/auth.go b/server/auth.go
index b7b95d36ce..270e82705a 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -61,7 +61,6 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
principalCreate := &api.PrincipalCreate{
CreatorId: api.SYSTEM_BOT_ID,
- Status: api.Active,
Type: api.EndUser,
Name: signup.Name,
Email: signup.Email,
@@ -78,6 +77,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
memberCreate := &api.MemberCreate{
CreatorId: api.SYSTEM_BOT_ID,
+ Status: api.Active,
Role: api.Developer,
PrincipalId: user.ID,
}
diff --git a/server/principal.go b/server/principal.go
index e315f37abc..f071af426c 100644
--- a/server/principal.go
+++ b/server/principal.go
@@ -20,7 +20,6 @@ func (s *Server) registerPrincipalRoutes(g *echo.Group) {
}
principalCreate.CreatorId = c.Get(GetPrincipalIdContextKey()).(int)
- principalCreate.Status = api.Invited
principalCreate.Type = api.EndUser
principalCreate.PasswordHash = ""
diff --git a/store/member.go b/store/member.go
index 1f8d6c9475..feb5e941bb 100644
--- a/store/member.go
+++ b/store/member.go
@@ -131,14 +131,16 @@ func createMember(ctx context.Context, tx *Tx, create *api.MemberCreate) (*api.M
INSERT INTO member (
creator_id,
updater_id,
+ `+"`status`,"+`
role,
principal_id
)
- VALUES (?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, role, principal_id
+ VALUES (?, ?, ?, ?, ?)
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, `+"`status`, role, principal_id"+`
`,
create.CreatorId,
create.CreatorId,
+ create.Status,
create.Role,
create.PrincipalId,
)
@@ -156,6 +158,7 @@ func createMember(ctx context.Context, tx *Tx, create *api.MemberCreate) (*api.M
&member.CreatedTs,
&member.UpdaterId,
&member.UpdatedTs,
+ &member.Status,
&member.Role,
&member.PrincipalId,
); err != nil {
@@ -182,6 +185,7 @@ func findMemberList(ctx context.Context, tx *Tx, find *api.MemberFind) (_ []*api
created_ts,
updater_id,
updated_ts,
+ `+"`status`,"+`
role,
principal_id
FROM member
@@ -203,6 +207,7 @@ func findMemberList(ctx context.Context, tx *Tx, find *api.MemberFind) (_ []*api
&member.CreatedTs,
&member.UpdaterId,
&member.UpdatedTs,
+ &member.Status,
&member.Role,
&member.PrincipalId,
); err != nil {
diff --git a/store/migration/0001_init_schema.up.sql b/store/migration/0001_init_schema.up.sql
index 2115a05f08..8d1b507601 100644
--- a/store/migration/0001_init_schema.up.sql
+++ b/store/migration/0001_init_schema.up.sql
@@ -8,7 +8,6 @@ CREATE TABLE principal (
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- `status` TEXT NOT NULL CHECK (`status` IN ('INVITED', 'ACTIVE')),
`type` TEXT NOT NULL CHECK (`type` IN ('END_USER', 'SYSTEM_BOT')),
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
@@ -39,7 +38,6 @@ INSERT INTO
id,
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -50,7 +48,6 @@ VALUES
1,
1,
1,
- 'ACTIVE',
'SYSTEM_BOT',
'Bytebase',
@@ -67,6 +64,7 @@ CREATE TABLE member (
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ `status` TEXT NOT NULL CHECK (`status` IN ('INVITED', 'ACTIVE')),
`role` TEXT NOT NULL CHECK (
`role` IN ('OWNER', 'DBA', 'DEVELOPER')
),
diff --git a/store/principal.go b/store/principal.go
index 8c3884f641..71c5b8e703 100644
--- a/store/principal.go
+++ b/store/principal.go
@@ -110,18 +110,16 @@ func createPrincipal(ctx context.Context, tx *Tx, create *api.PrincipalCreate) (
INSERT INTO principal (
creator_id,
updater_id,
- status,
type,
name,
email,
password_hash
)
- VALUES (?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, status, type, name, email, password_hash
+ VALUES (?, ?, ?, ?, ?, ?)
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, name, email, password_hash
`,
create.CreatorId,
create.CreatorId,
- create.Status,
create.Type,
create.Name,
create.Email,
@@ -141,7 +139,6 @@ func createPrincipal(ctx context.Context, tx *Tx, create *api.PrincipalCreate) (
&principal.CreatedTs,
&principal.UpdaterId,
&principal.UpdatedTs,
- &principal.Status,
&principal.Type,
&principal.Name,
&principal.Email,
@@ -170,7 +167,6 @@ func findPrincipalList(ctx context.Context, tx *Tx, find *api.PrincipalFind) (_
created_ts,
updater_id,
updated_ts,
- status,
type,
name,
email,
@@ -194,7 +190,6 @@ func findPrincipalList(ctx context.Context, tx *Tx, find *api.PrincipalFind) (_
&principal.CreatedTs,
&principal.UpdaterId,
&principal.UpdatedTs,
- &principal.Status,
&principal.Type,
&principal.Name,
&principal.Email,
@@ -225,7 +220,7 @@ func patchPrincipal(ctx context.Context, tx *Tx, patch *api.PrincipalPatch) (*ap
UPDATE principal
SET name = ?, updater_id = ?
WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, status, type, name, email, password_hash
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, name, email, password_hash
`,
principal.Name,
patch.UpdaterId,
@@ -244,7 +239,6 @@ func patchPrincipal(ctx context.Context, tx *Tx, patch *api.PrincipalPatch) (*ap
&principal.CreatedTs,
&principal.UpdaterId,
&principal.UpdatedTs,
- &principal.Status,
&principal.Type,
&principal.Name,
&principal.Email,
diff --git a/store/seed/demo/0001_principal.sql b/store/seed/demo/0001_principal.sql
index ca1b1a7eba..2d75ef3e92 100644
--- a/store/seed/demo/0001_principal.sql
+++ b/store/seed/demo/0001_principal.sql
@@ -5,7 +5,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -15,7 +14,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Demo Owner',
@@ -28,7 +26,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -38,7 +35,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Jerry DBA',
@@ -51,7 +47,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -61,7 +56,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Tom Dev',
@@ -74,7 +68,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -84,7 +77,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Jane Dev',
diff --git a/store/seed/demo/0020_member.sql b/store/seed/demo/0020_member.sql
index c868a066ce..697e4842ca 100644
--- a/store/seed/demo/0020_member.sql
+++ b/store/seed/demo/0020_member.sql
@@ -3,41 +3,45 @@ INSERT INTO
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2001, 101, 101, 'OWNER', 101);
+ (2001, 101, 101, 'ACTIVE', 'OWNER', 101);
INSERT INTO
member (
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2002, 101, 101, 'DBA', 102);
+ (2002, 101, 101, 'ACTIVE', 'DBA', 102);
INSERT INTO
member (
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2003, 101, 101, 'DEVELOPER', 103);
+ (2003, 101, 101, 'ACTIVE', 'DEVELOPER', 103);
INSERT INTO
member (
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2004, 101, 101, 'DEVELOPER', 104);
\ No newline at end of file
+ (2004, 101, 101, 'ACTIVE', 'DEVELOPER', 104);
\ No newline at end of file
diff --git a/store/seed/dev/0001_principal.sql b/store/seed/dev/0001_principal.sql
index ca1b1a7eba..2d75ef3e92 100644
--- a/store/seed/dev/0001_principal.sql
+++ b/store/seed/dev/0001_principal.sql
@@ -5,7 +5,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -15,7 +14,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Demo Owner',
@@ -28,7 +26,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -38,7 +35,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Jerry DBA',
@@ -51,7 +47,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -61,7 +56,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Tom Dev',
@@ -74,7 +68,6 @@ INSERT INTO
principal (
creator_id,
updater_id,
- `status`,
`type`,
name,
email,
@@ -84,7 +77,6 @@ VALUES
(
1,
1,
- 'ACTIVE',
'END_USER',
'Jane Dev',
diff --git a/store/seed/dev/0020_member.sql b/store/seed/dev/0020_member.sql
index c868a066ce..697e4842ca 100644
--- a/store/seed/dev/0020_member.sql
+++ b/store/seed/dev/0020_member.sql
@@ -3,41 +3,45 @@ INSERT INTO
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2001, 101, 101, 'OWNER', 101);
+ (2001, 101, 101, 'ACTIVE', 'OWNER', 101);
INSERT INTO
member (
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2002, 101, 101, 'DBA', 102);
+ (2002, 101, 101, 'ACTIVE', 'DBA', 102);
INSERT INTO
member (
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2003, 101, 101, 'DEVELOPER', 103);
+ (2003, 101, 101, 'ACTIVE', 'DEVELOPER', 103);
INSERT INTO
member (
id,
creator_id,
updater_id,
+ `status`,
role,
principal_id
)
VALUES
- (2004, 101, 101, 'DEVELOPER', 104);
\ No newline at end of file
+ (2004, 101, 101, 'ACTIVE', 'DEVELOPER', 104);
\ No newline at end of file