@companyhelm/cli 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/cli_io_interface.d.ts +10 -0
  2. package/dist/cli_io_interface.js +2 -0
  3. package/dist/cli_io_interface.js.map +1 -0
  4. package/dist/companyhelm_cli.d.ts +20 -0
  5. package/dist/companyhelm_cli.js +73 -0
  6. package/dist/companyhelm_cli.js.map +1 -0
  7. package/dist/console_io.d.ts +9 -0
  8. package/dist/console_io.js +13 -0
  9. package/dist/console_io.js.map +1 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +4 -0
  12. package/dist/index.js.map +1 -0
  13. package/package.json +20 -28
  14. package/LICENSE +0 -21
  15. package/README.md +0 -66
  16. package/dist/cli.d.ts +0 -2
  17. package/dist/cli.js +0 -39
  18. package/dist/commands/dependencies.d.ts +0 -28
  19. package/dist/commands/dependencies.js +0 -292
  20. package/dist/commands/down.d.ts +0 -3
  21. package/dist/commands/down.js +0 -5
  22. package/dist/commands/interactive.d.ts +0 -7
  23. package/dist/commands/interactive.js +0 -25
  24. package/dist/commands/logs.d.ts +0 -3
  25. package/dist/commands/logs.js +0 -14
  26. package/dist/commands/register-commands.d.ts +0 -3
  27. package/dist/commands/register-commands.js +0 -23
  28. package/dist/commands/reset.d.ts +0 -7
  29. package/dist/commands/reset.js +0 -51
  30. package/dist/commands/set-image-version.d.ts +0 -31
  31. package/dist/commands/set-image-version.js +0 -87
  32. package/dist/commands/setup-github-app.d.ts +0 -13
  33. package/dist/commands/setup-github-app.js +0 -233
  34. package/dist/commands/startup-preferences.d.ts +0 -3
  35. package/dist/commands/startup-preferences.js +0 -39
  36. package/dist/commands/status.d.ts +0 -3
  37. package/dist/commands/status.js +0 -7
  38. package/dist/commands/up.d.ts +0 -3
  39. package/dist/commands/up.js +0 -39
  40. package/dist/core/bootstrap/DeploymentBootstrapper.d.ts +0 -15
  41. package/dist/core/bootstrap/DeploymentBootstrapper.js +0 -118
  42. package/dist/core/bootstrap/SeedSqlRenderer.d.ts +0 -12
  43. package/dist/core/bootstrap/SeedSqlRenderer.js +0 -44
  44. package/dist/core/config/ApiEnvFileWriter.d.ts +0 -8
  45. package/dist/core/config/ApiEnvFileWriter.js +0 -33
  46. package/dist/core/config/GithubAppConfig.d.ts +0 -6
  47. package/dist/core/config/GithubAppConfig.js +0 -26
  48. package/dist/core/config/GithubAppConfigStore.d.ts +0 -11
  49. package/dist/core/config/GithubAppConfigStore.js +0 -57
  50. package/dist/core/docker/ComposeTemplateRenderer.d.ts +0 -22
  51. package/dist/core/docker/ComposeTemplateRenderer.js +0 -66
  52. package/dist/core/docker/DockerStackManager.d.ts +0 -29
  53. package/dist/core/docker/DockerStackManager.js +0 -163
  54. package/dist/core/local/ApiLocalService.d.ts +0 -22
  55. package/dist/core/local/ApiLocalService.js +0 -65
  56. package/dist/core/local/LocalRepoSourceResolver.d.ts +0 -24
  57. package/dist/core/local/LocalRepoSourceResolver.js +0 -33
  58. package/dist/core/local/LocalServiceProcessManager.d.ts +0 -18
  59. package/dist/core/local/LocalServiceProcessManager.js +0 -83
  60. package/dist/core/local/WebLocalService.d.ts +0 -23
  61. package/dist/core/local/WebLocalService.js +0 -101
  62. package/dist/core/logs/LogsService.d.ts +0 -6
  63. package/dist/core/logs/LogsService.js +0 -14
  64. package/dist/core/process/CommandRunner.d.ts +0 -4
  65. package/dist/core/process/CommandRunner.js +0 -51
  66. package/dist/core/runner/RunnerSupervisor.d.ts +0 -29
  67. package/dist/core/runner/RunnerSupervisor.js +0 -90
  68. package/dist/core/runner/runner-bootstrap.d.ts +0 -2
  69. package/dist/core/runner/runner-bootstrap.js +0 -48
  70. package/dist/core/runtime/CliPackageMetadata.d.ts +0 -3
  71. package/dist/core/runtime/CliPackageMetadata.js +0 -8
  72. package/dist/core/runtime/CliRoot.d.ts +0 -2
  73. package/dist/core/runtime/CliRoot.js +0 -23
  74. package/dist/core/runtime/ImageCatalog.d.ts +0 -8
  75. package/dist/core/runtime/ImageCatalog.js +0 -12
  76. package/dist/core/runtime/LocalConfigStore.d.ts +0 -16
  77. package/dist/core/runtime/LocalConfigStore.js +0 -50
  78. package/dist/core/runtime/ManagedImages.d.ts +0 -10
  79. package/dist/core/runtime/ManagedImages.js +0 -27
  80. package/dist/core/runtime/PortAllocator.d.ts +0 -9
  81. package/dist/core/runtime/PortAllocator.js +0 -20
  82. package/dist/core/runtime/PublicImageTagRegistry.d.ts +0 -17
  83. package/dist/core/runtime/PublicImageTagRegistry.js +0 -168
  84. package/dist/core/runtime/RepoConfigStore.d.ts +0 -16
  85. package/dist/core/runtime/RepoConfigStore.js +0 -63
  86. package/dist/core/runtime/RuntimePaths.d.ts +0 -16
  87. package/dist/core/runtime/RuntimePaths.js +0 -43
  88. package/dist/core/runtime/RuntimeState.d.ts +0 -38
  89. package/dist/core/runtime/RuntimeState.js +0 -1
  90. package/dist/core/runtime/RuntimeStateStore.d.ts +0 -11
  91. package/dist/core/runtime/RuntimeStateStore.js +0 -81
  92. package/dist/core/runtime/Secrets.d.ts +0 -10
  93. package/dist/core/runtime/Secrets.js +0 -26
  94. package/dist/core/runtime/VersionCatalog.d.ts +0 -10
  95. package/dist/core/runtime/VersionCatalog.js +0 -21
  96. package/dist/core/services/ManagedServiceNames.d.ts +0 -5
  97. package/dist/core/services/ManagedServiceNames.js +0 -12
  98. package/dist/core/status/StatusService.d.ts +0 -19
  99. package/dist/core/status/StatusService.js +0 -30
  100. package/dist/core/ui/TerminalRenderer.d.ts +0 -17
  101. package/dist/core/ui/TerminalRenderer.js +0 -71
  102. package/dist/preflight/ApiPortPreflightCheck.d.ts +0 -6
  103. package/dist/preflight/ApiPortPreflightCheck.js +0 -10
  104. package/dist/preflight/DockerInstalledPreflightCheck.d.ts +0 -7
  105. package/dist/preflight/DockerInstalledPreflightCheck.js +0 -15
  106. package/dist/preflight/PortAvailabilityPreflightCheck.d.ts +0 -7
  107. package/dist/preflight/PortAvailabilityPreflightCheck.js +0 -31
  108. package/dist/preflight/PostgresPortPreflightCheck.d.ts +0 -6
  109. package/dist/preflight/PostgresPortPreflightCheck.js +0 -10
  110. package/dist/preflight/PreflightCheck.d.ts +0 -3
  111. package/dist/preflight/PreflightCheck.js +0 -1
  112. package/dist/preflight/WebPortPreflightCheck.d.ts +0 -6
  113. package/dist/preflight/WebPortPreflightCheck.js +0 -10
  114. package/dist/preflight/runStartupPreflightChecks.d.ts +0 -18
  115. package/dist/preflight/runStartupPreflightChecks.js +0 -42
  116. package/dist/templates/api.env.tpl +0 -3
  117. package/dist/templates/docker-compose.yaml.tpl +0 -24
  118. package/dist/templates/seed.sql.tpl +0 -76
  119. package/src/templates/api.env.tpl +0 -3
  120. package/src/templates/docker-compose.yaml.tpl +0 -24
  121. package/src/templates/seed.sql.tpl +0 -76
@@ -1,71 +0,0 @@
1
- import chalk from "chalk";
2
- import figlet from "figlet";
3
- export class TerminalRenderer {
4
- useColor;
5
- static OSC = "\u001B]";
6
- static BEL = "\u0007";
7
- constructor(useColor = true) {
8
- this.useColor = useColor;
9
- }
10
- renderBanner() {
11
- const banner = figlet.textSync("COMPANYHELM", {
12
- horizontalLayout: "fitted"
13
- });
14
- return this.colorize(`COMPANYHELM\n${banner}`, "cyan");
15
- }
16
- success(message) {
17
- return `${this.colorize("[ok]", "green")} ${message}`;
18
- }
19
- progress(message) {
20
- return this.colorize(`... ${message}`, "cyan");
21
- }
22
- successHighlight(message) {
23
- if (!this.useColor) {
24
- return message;
25
- }
26
- return chalk.green.bold(message);
27
- }
28
- clickableUrl(url) {
29
- if (!this.useColor) {
30
- return url;
31
- }
32
- const display = this.successHighlight(url);
33
- return `${TerminalRenderer.OSC}8;;${url}${TerminalRenderer.BEL}${display}${TerminalRenderer.OSC}8;;${TerminalRenderer.BEL}`;
34
- }
35
- renderStatus(report) {
36
- const lines = ["Status"];
37
- lines.push(this.renderServiceLine("Postgres", report.services.postgres));
38
- lines.push(this.renderServiceLine("API", report.services.api, report.apiUrl));
39
- lines.push(this.renderServiceLine("companyhelm-web", report.services.frontend, report.uiUrl));
40
- lines.push(this.renderServiceLine("Runner", report.services.runner));
41
- if (report.versions) {
42
- lines.push(`CompanyHelm CLI: ${report.versions.cliPackage}`);
43
- lines.push(`Runner package: ${report.versions.runnerPackage}`);
44
- lines.push(`API image: ${report.versions.images.api}`);
45
- lines.push(`companyhelm-web image: ${report.versions.images.frontend}`);
46
- lines.push(`Postgres image: ${report.versions.images.postgres}`);
47
- }
48
- if (report.username) {
49
- lines.push(`username: ${report.username}`);
50
- }
51
- return lines.join("\n");
52
- }
53
- renderServiceLine(label, status, detail) {
54
- const statusLabel = status === "running" ? this.success("running") : this.warn("stopped");
55
- return detail && status === "running"
56
- ? `${label}: ${statusLabel} (${this.formatDetail(detail)})`
57
- : `${label}: ${statusLabel}`;
58
- }
59
- warn(message) {
60
- return `${this.colorize("[!]", "yellow")} ${message}`;
61
- }
62
- formatDetail(detail) {
63
- return detail.startsWith("http://") || detail.startsWith("https://") ? this.clickableUrl(detail) : detail;
64
- }
65
- colorize(text, color) {
66
- if (!this.useColor) {
67
- return text;
68
- }
69
- return chalk[color](text);
70
- }
71
- }
@@ -1,6 +0,0 @@
1
- import type { PreflightCheck } from "./PreflightCheck.js";
2
- export declare class ApiPortPreflightCheck implements PreflightCheck {
3
- private readonly delegate;
4
- constructor(port: number);
5
- run(): Promise<void>;
6
- }
@@ -1,10 +0,0 @@
1
- import { PortAvailabilityPreflightCheck } from "./PortAvailabilityPreflightCheck.js";
2
- export class ApiPortPreflightCheck {
3
- delegate;
4
- constructor(port) {
5
- this.delegate = new PortAvailabilityPreflightCheck("companyhelm-api", port);
6
- }
7
- run() {
8
- return this.delegate.run();
9
- }
10
- }
@@ -1,7 +0,0 @@
1
- import { CommandRunner } from "../core/process/CommandRunner.js";
2
- import type { PreflightCheck } from "./PreflightCheck.js";
3
- export declare class DockerInstalledPreflightCheck implements PreflightCheck {
4
- private readonly commandRunner;
5
- constructor(commandRunner?: CommandRunner);
6
- run(): Promise<void>;
7
- }
@@ -1,15 +0,0 @@
1
- import { CommandRunner } from "../core/process/CommandRunner.js";
2
- export class DockerInstalledPreflightCheck {
3
- commandRunner;
4
- constructor(commandRunner = new CommandRunner()) {
5
- this.commandRunner = commandRunner;
6
- }
7
- async run() {
8
- try {
9
- await this.commandRunner.capture("docker", ["--version"]);
10
- }
11
- catch {
12
- throw new Error("Docker is required for `companyhelm up`, but the `docker` command is unavailable. Install Docker and make sure it is on your PATH.");
13
- }
14
- }
15
- }
@@ -1,7 +0,0 @@
1
- import type { PreflightCheck } from "./PreflightCheck.js";
2
- export declare class PortAvailabilityPreflightCheck implements PreflightCheck {
3
- private readonly serviceName;
4
- private readonly port;
5
- constructor(serviceName: string, port: number);
6
- run(): Promise<void>;
7
- }
@@ -1,31 +0,0 @@
1
- import net from "node:net";
2
- export class PortAvailabilityPreflightCheck {
3
- serviceName;
4
- port;
5
- constructor(serviceName, port) {
6
- this.serviceName = serviceName;
7
- this.port = port;
8
- }
9
- async run() {
10
- await new Promise((resolve, reject) => {
11
- const server = net.createServer();
12
- server.once("error", (error) => {
13
- if (error.code === "EADDRINUSE") {
14
- reject(new Error(`${this.serviceName} cannot start because port ${this.port} is already in use.`));
15
- return;
16
- }
17
- reject(new Error(`${this.serviceName} cannot verify port ${this.port}: ${error.message}`));
18
- });
19
- server.once("listening", () => {
20
- server.close((closeError) => {
21
- if (closeError) {
22
- reject(closeError);
23
- return;
24
- }
25
- resolve();
26
- });
27
- });
28
- server.listen(this.port, "0.0.0.0");
29
- });
30
- }
31
- }
@@ -1,6 +0,0 @@
1
- import type { PreflightCheck } from "./PreflightCheck.js";
2
- export declare class PostgresPortPreflightCheck implements PreflightCheck {
3
- private readonly delegate;
4
- constructor(port?: number);
5
- run(): Promise<void>;
6
- }
@@ -1,10 +0,0 @@
1
- import { PortAvailabilityPreflightCheck } from "./PortAvailabilityPreflightCheck.js";
2
- export class PostgresPortPreflightCheck {
3
- delegate;
4
- constructor(port = 5432) {
5
- this.delegate = new PortAvailabilityPreflightCheck("Postgres", port);
6
- }
7
- run() {
8
- return this.delegate.run();
9
- }
10
- }
@@ -1,3 +0,0 @@
1
- export interface PreflightCheck {
2
- run(): Promise<void>;
3
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { PreflightCheck } from "./PreflightCheck.js";
2
- export declare class WebPortPreflightCheck implements PreflightCheck {
3
- private readonly delegate;
4
- constructor(port: number);
5
- run(): Promise<void>;
6
- }
@@ -1,10 +0,0 @@
1
- import { PortAvailabilityPreflightCheck } from "./PortAvailabilityPreflightCheck.js";
2
- export class WebPortPreflightCheck {
3
- delegate;
4
- constructor(port) {
5
- this.delegate = new PortAvailabilityPreflightCheck("companyhelm-web", port);
6
- }
7
- run() {
8
- return this.delegate.run();
9
- }
10
- }
@@ -1,18 +0,0 @@
1
- import type { ResolvedServiceSources } from "../core/local/LocalRepoSourceResolver.js";
2
- import type { CommandRunner } from "../core/process/CommandRunner.js";
3
- import type { RuntimePorts, RuntimeState } from "../core/runtime/RuntimeState.js";
4
- import type { ManagedServiceStatus } from "../core/status/StatusService.js";
5
- interface StartupStatusSnapshot {
6
- postgres: ManagedServiceStatus;
7
- api: ManagedServiceStatus;
8
- frontend: ManagedServiceStatus;
9
- }
10
- interface StartupPreflightOptions {
11
- commandRunner: CommandRunner;
12
- currentState: RuntimeState | null;
13
- desiredSources: ResolvedServiceSources;
14
- ports: RuntimePorts;
15
- readStatus: () => Promise<StartupStatusSnapshot>;
16
- }
17
- export declare function runStartupPreflightChecks(options: StartupPreflightOptions): Promise<void>;
18
- export {};
@@ -1,42 +0,0 @@
1
- import { DockerInstalledPreflightCheck } from "./DockerInstalledPreflightCheck.js";
2
- import { ApiPortPreflightCheck } from "./ApiPortPreflightCheck.js";
3
- import { PostgresPortPreflightCheck } from "./PostgresPortPreflightCheck.js";
4
- import { WebPortPreflightCheck } from "./WebPortPreflightCheck.js";
5
- export async function runStartupPreflightChecks(options) {
6
- await new DockerInstalledPreflightCheck(options.commandRunner).run();
7
- const currentStatus = await options.readStatus();
8
- if (shouldCheckApiPort(options, currentStatus)) {
9
- await new ApiPortPreflightCheck(options.ports.apiHttp).run();
10
- }
11
- if (shouldCheckWebPort(options, currentStatus)) {
12
- await new WebPortPreflightCheck(options.ports.ui).run();
13
- }
14
- if (shouldCheckPostgresPort(options, currentStatus)) {
15
- await new PostgresPortPreflightCheck().run();
16
- }
17
- }
18
- function shouldCheckApiPort(options, currentStatus) {
19
- return shouldCheckServicePort("api", options.currentState, currentStatus.api, options.desiredSources.api.source);
20
- }
21
- function shouldCheckWebPort(options, currentStatus) {
22
- return shouldCheckServicePort("frontend", options.currentState, currentStatus.frontend, options.desiredSources.frontend.source);
23
- }
24
- function shouldCheckPostgresPort(options, currentStatus) {
25
- if (options.desiredSources.api.source !== "local") {
26
- return false;
27
- }
28
- return currentStatus.postgres !== "running";
29
- }
30
- function shouldCheckServicePort(service, currentState, currentStatus, desiredSource) {
31
- if (currentStatus !== "running") {
32
- return true;
33
- }
34
- const currentService = currentState?.services[service];
35
- if (!currentService) {
36
- return true;
37
- }
38
- if (currentService.source === "docker") {
39
- return desiredSource !== "docker";
40
- }
41
- return false;
42
- }
@@ -1,3 +0,0 @@
1
- GITHUB_APP_URL={{GITHUB_APP_URL}}
2
- GITHUB_APP_CLIENT_ID={{GITHUB_APP_CLIENT_ID}}
3
- GITHUB_APP_PRIVATE_KEY_PEM={{GITHUB_APP_PRIVATE_KEY_PEM}}
@@ -1,24 +0,0 @@
1
- services:
2
- postgres:
3
- image: {{POSTGRES_IMAGE}}
4
- environment:
5
- POSTGRES_USER: postgres
6
- POSTGRES_PASSWORD: postgres
7
- POSTGRES_DB: companyhelm
8
- {{POSTGRES_PORTS_BLOCK}}
9
- volumes:
10
- - companyhelm_postgres_data:/var/lib/postgresql/data
11
- - "{{SEED_FILE_PATH}}:/run/companyhelm/seed.sql:ro"
12
- networks:
13
- - companyhelm
14
-
15
- {{API_SERVICE_BLOCK}}
16
-
17
- {{FRONTEND_SERVICE_BLOCK}}
18
-
19
- networks:
20
- companyhelm:
21
- driver: bridge
22
-
23
- volumes:
24
- companyhelm_postgres_data:
@@ -1,76 +0,0 @@
1
- BEGIN;
2
-
3
- INSERT INTO companies (id, name)
4
- VALUES ('{{COMPANY_ID}}', '{{COMPANY_NAME}}')
5
- ON CONFLICT (id) DO UPDATE
6
- SET name = EXCLUDED.name;
7
-
8
- UPDATE users
9
- SET first_name = '{{USER_FIRST_NAME}}',
10
- last_name = NULL,
11
- email = '{{USER_EMAIL}}',
12
- auth_provider = 'companyhelm',
13
- updated_at = NOW()
14
- WHERE id = '{{USER_ID}}'
15
- OR email = '{{USER_EMAIL}}';
16
-
17
- INSERT INTO users (id, first_name, last_name, email, auth_provider, created_at, updated_at)
18
- SELECT
19
- '{{USER_ID}}',
20
- '{{USER_FIRST_NAME}}',
21
- NULL,
22
- '{{USER_EMAIL}}',
23
- 'companyhelm',
24
- NOW(),
25
- NOW()
26
- WHERE NOT EXISTS (
27
- SELECT 1
28
- FROM users
29
- WHERE id = '{{USER_ID}}'
30
- OR email = '{{USER_EMAIL}}'
31
- );
32
-
33
- UPDATE user_auths
34
- SET user_id = '{{USER_ID}}',
35
- email = '{{USER_EMAIL}}',
36
- password_salt = '{{PASSWORD_SALT}}',
37
- password_hash = '{{PASSWORD_HASH}}',
38
- updated_at = NOW()
39
- WHERE user_id = '{{USER_ID}}'
40
- OR email = '{{USER_EMAIL}}';
41
-
42
- INSERT INTO user_auths (id, user_id, email, password_salt, password_hash, created_at, updated_at)
43
- SELECT
44
- '{{USER_AUTH_ID}}',
45
- '{{USER_ID}}',
46
- '{{USER_EMAIL}}',
47
- '{{PASSWORD_SALT}}',
48
- '{{PASSWORD_HASH}}',
49
- NOW(),
50
- NOW()
51
- WHERE NOT EXISTS (
52
- SELECT 1
53
- FROM user_auths
54
- WHERE user_id = '{{USER_ID}}'
55
- OR email = '{{USER_EMAIL}}'
56
- );
57
-
58
- INSERT INTO company_members (company_id, user_id)
59
- VALUES ('{{COMPANY_ID}}', '{{USER_ID}}')
60
- ON CONFLICT (company_id, user_id) DO NOTHING;
61
-
62
- INSERT INTO agent_runners (id, company_id, secret_hash, status, name)
63
- VALUES (
64
- '{{RUNNER_ID}}',
65
- '{{COMPANY_ID}}',
66
- '{{RUNNER_SECRET_HASH}}',
67
- 'ready',
68
- '{{RUNNER_NAME}}'
69
- )
70
- ON CONFLICT (id) DO UPDATE
71
- SET company_id = EXCLUDED.company_id,
72
- secret_hash = EXCLUDED.secret_hash,
73
- status = EXCLUDED.status,
74
- name = EXCLUDED.name;
75
-
76
- COMMIT;
@@ -1,3 +0,0 @@
1
- GITHUB_APP_URL={{GITHUB_APP_URL}}
2
- GITHUB_APP_CLIENT_ID={{GITHUB_APP_CLIENT_ID}}
3
- GITHUB_APP_PRIVATE_KEY_PEM={{GITHUB_APP_PRIVATE_KEY_PEM}}
@@ -1,24 +0,0 @@
1
- services:
2
- postgres:
3
- image: {{POSTGRES_IMAGE}}
4
- environment:
5
- POSTGRES_USER: postgres
6
- POSTGRES_PASSWORD: postgres
7
- POSTGRES_DB: companyhelm
8
- {{POSTGRES_PORTS_BLOCK}}
9
- volumes:
10
- - companyhelm_postgres_data:/var/lib/postgresql/data
11
- - "{{SEED_FILE_PATH}}:/run/companyhelm/seed.sql:ro"
12
- networks:
13
- - companyhelm
14
-
15
- {{API_SERVICE_BLOCK}}
16
-
17
- {{FRONTEND_SERVICE_BLOCK}}
18
-
19
- networks:
20
- companyhelm:
21
- driver: bridge
22
-
23
- volumes:
24
- companyhelm_postgres_data:
@@ -1,76 +0,0 @@
1
- BEGIN;
2
-
3
- INSERT INTO companies (id, name)
4
- VALUES ('{{COMPANY_ID}}', '{{COMPANY_NAME}}')
5
- ON CONFLICT (id) DO UPDATE
6
- SET name = EXCLUDED.name;
7
-
8
- UPDATE users
9
- SET first_name = '{{USER_FIRST_NAME}}',
10
- last_name = NULL,
11
- email = '{{USER_EMAIL}}',
12
- auth_provider = 'companyhelm',
13
- updated_at = NOW()
14
- WHERE id = '{{USER_ID}}'
15
- OR email = '{{USER_EMAIL}}';
16
-
17
- INSERT INTO users (id, first_name, last_name, email, auth_provider, created_at, updated_at)
18
- SELECT
19
- '{{USER_ID}}',
20
- '{{USER_FIRST_NAME}}',
21
- NULL,
22
- '{{USER_EMAIL}}',
23
- 'companyhelm',
24
- NOW(),
25
- NOW()
26
- WHERE NOT EXISTS (
27
- SELECT 1
28
- FROM users
29
- WHERE id = '{{USER_ID}}'
30
- OR email = '{{USER_EMAIL}}'
31
- );
32
-
33
- UPDATE user_auths
34
- SET user_id = '{{USER_ID}}',
35
- email = '{{USER_EMAIL}}',
36
- password_salt = '{{PASSWORD_SALT}}',
37
- password_hash = '{{PASSWORD_HASH}}',
38
- updated_at = NOW()
39
- WHERE user_id = '{{USER_ID}}'
40
- OR email = '{{USER_EMAIL}}';
41
-
42
- INSERT INTO user_auths (id, user_id, email, password_salt, password_hash, created_at, updated_at)
43
- SELECT
44
- '{{USER_AUTH_ID}}',
45
- '{{USER_ID}}',
46
- '{{USER_EMAIL}}',
47
- '{{PASSWORD_SALT}}',
48
- '{{PASSWORD_HASH}}',
49
- NOW(),
50
- NOW()
51
- WHERE NOT EXISTS (
52
- SELECT 1
53
- FROM user_auths
54
- WHERE user_id = '{{USER_ID}}'
55
- OR email = '{{USER_EMAIL}}'
56
- );
57
-
58
- INSERT INTO company_members (company_id, user_id)
59
- VALUES ('{{COMPANY_ID}}', '{{USER_ID}}')
60
- ON CONFLICT (company_id, user_id) DO NOTHING;
61
-
62
- INSERT INTO agent_runners (id, company_id, secret_hash, status, name)
63
- VALUES (
64
- '{{RUNNER_ID}}',
65
- '{{COMPANY_ID}}',
66
- '{{RUNNER_SECRET_HASH}}',
67
- 'ready',
68
- '{{RUNNER_NAME}}'
69
- )
70
- ON CONFLICT (id) DO UPDATE
71
- SET company_id = EXCLUDED.company_id,
72
- secret_hash = EXCLUDED.secret_hash,
73
- status = EXCLUDED.status,
74
- name = EXCLUDED.name;
75
-
76
- COMMIT;