Skip to content

Commit f585826

Browse files
committed
feat(cli): add root account option
1 parent 31789c1 commit f585826

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

packages/cli/src/actions/sync.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export default async function sync(options: {
9999
await driver.createUser({
100100
username: account.username,
101101
password: password,
102+
root: account.root,
102103
});
103104
log("success", alias, "User created");
104105
} else {

packages/cli/src/drivers/DriverAbstract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type GlobalOptions = RootAccount & {
1414
export type CreateUserOptions = {
1515
username: string;
1616
password: Password;
17+
root?: boolean;
1718
};
1819

1920
export type CreateDatabaseOptions = {

packages/cli/src/drivers/MysqlDriver.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ import {
1313
export default class MysqlDriver extends DriverAbstract {
1414
override async createUser(options: CreateUserOptions) {
1515
const password = await parsePassword(options.password);
16+
const { username } = options;
1617
await this.query(
17-
`CREATE USER '${options.username}'@'%' IDENTIFIED BY '${password}';`
18+
`CREATE USER '${username}'@'%' IDENTIFIED BY '${password}';`
1819
);
20+
if (options.root)
21+
await this.query(
22+
`GRANT ALL PRIVILEGES ON *.* TO '${username}'@'%' WITH GRANT OPTION;`
23+
);
1924
}
2025

2126
override async createDatabase(options: CreateDatabaseOptions) {

packages/cli/src/drivers/PostgresDriver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import {
1313
export default class PostgresDriver extends DriverAbstract {
1414
override async createUser(options: CreateUserOptions) {
1515
const password = await parsePassword(options.password);
16+
const { username } = options;
1617
await this.query(
17-
`CREATE USER "${options.username}" WITH ENCRYPTED PASSWORD '${password}';`
18+
`CREATE USER "${username}" WITH ENCRYPTED PASSWORD '${password}';`
1819
);
20+
if (options.root) await this.query(`ALTER ROLE "${username}" SUPERUSER;`);
1921
}
2022

2123
override async createDatabase(options: CreateDatabaseOptions) {

packages/cli/src/utils/self/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export type RootAccount = {
8484
export type Account = {
8585
username: string;
8686
password: Password;
87+
root?: boolean;
8788
createDatabase?: boolean;
8889
/**
8990
* @default createDatabase

0 commit comments

Comments
 (0)