-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor initialize sql script to compatible with ce and ee #79
Conversation
WalkthroughThis pull request updates the database initialization process across multiple deployment configurations (Docker Compose, Docker, and Helm Chart). The primary change involves replacing the Changes
Possibly related PRs
Suggested reviewers
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
The TipsCodeReview Commands (invoked as MR or PR comments)
CodeReview Discussion ChatThere are 2 ways to chat with Starship CodeReview:
Note: Be mindful of the bot's finite context window. CodeReview Documentation and Community
|
cff64a4
to
39883fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (5)
docker/etc/server/initialize.sql (3)
Line range hint
1-24
: Consider enhancing the timestamp logging format.The current timestamp logging could be improved by including timezone information and a more descriptive format for better debugging and audit trails.
-SELECT now() as "Execute Timestamp"; +SELECT now() AT TIME ZONE 'UTC' as "Execute Timestamp (UTC)", + pg_backend_pid() as "Backend PID", + current_user as "Executing User";
160-306
: Add foreign key validation and indexing for runtime architectures.The current implementation doesn't enforce referential integrity between runtime architectures and frameworks. Consider adding foreign key constraints and appropriate indexes.
-- Add after the INSERT statement: ALTER TABLE public.runtime_architectures ADD CONSTRAINT fk_runtime_framework FOREIGN KEY (runtime_framework_id) REFERENCES public.runtime_frameworks(id); CREATE INDEX idx_runtime_architectures_framework_id ON public.runtime_architectures(runtime_framework_id);
Line range hint
1-316
: Consider centralizing database initialization scripts.Having identical initialization scripts in multiple locations (
docker/etc/server/
,helm-chart/charts/csghub/charts/server/
, anddocker-compose/init-scripts/
) could lead to maintenance issues and inconsistencies. Consider centralizing these scripts and using symlinks or a build process to distribute them.Suggested approaches:
- Create a single source of truth in a
database/migrations
directory- Use a build process to copy or link the file to required locations
- Consider using a database migration tool like Flyway or Liquibase for better version control
docker-compose/docker-compose.yml (2)
220-220
: Consider enhancing service resilience and observability.A few suggestions to improve the service configuration:
- Add a timeout to the health checks to prevent infinite waiting
- Add logging for initialization progress
- entrypoint: [ "sh", "-c", "until nc -zv csghub_server 8080 ; do echo 'sleep 10s...'; sleep 10; done; echo 'begin to do db init scripts'; until pg_isready -h postgres -p 5432; do sleep 5; done; psql -h postgres -U postgres -d starhub_server -f /scripts/initialize.sql" ] + entrypoint: [ "sh", "-c", "timeout 300 sh -c 'until nc -zv csghub_server 8080; do echo \"Waiting for csghub_server...\"; sleep 10; done' && \ + timeout 300 sh -c 'until pg_isready -h postgres -p 5432; do echo \"Waiting for postgres...\"; sleep 5; done' && \ + echo \"Starting database initialization...\" && \ + psql -h postgres -U postgres -d starhub_server -f /scripts/initialize.sql && \ + echo \"Database initialization completed successfully\"" ]
220-220
: Consider implementing initialization status tracking.To improve the robustness of the initialization process:
- Consider adding a status table or flag to track initialization state
- Implement idempotency to handle potential retries safely
This will help:
- Prevent duplicate initialization attempts
- Provide clear visibility into the initialization state
- Enable safe recovery in case of failures
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
docker-compose/docker-compose.yml
(1 hunks)docker-compose/init-scripts/init.sql
(0 hunks)docker-compose/init-scripts/initialize.sql
(1 hunks)docker/etc/server/initialize.sql
(2 hunks)helm-chart/charts/csghub/charts/server/initialize.sql
(2 hunks)
💤 Files with no reviewable changes (1)
- docker-compose/init-scripts/init.sql
🔇 Additional comments (3)
helm-chart/charts/csghub/charts/server/initialize.sql (1)
Line range hint 1-316
: Identical to docker/etc/server/initialize.sql
This file is identical to the previously reviewed file. Please refer to the comments above.
docker-compose/init-scripts/initialize.sql (1)
1-316
: Identical to docker/etc/server/initialize.sql
This file is identical to the previously reviewed file. Please refer to the comments above.
docker-compose/docker-compose.yml (1)
220-220
: Verify the initialization script's existence and permissions.
The entrypoint command looks robust with proper health checks. However, we should verify that the new initialize.sql
script exists in the mounted volume.
✅ Verification successful
The initialization script exists and contains valid SQL statements
The initialize.sql
script is present at the expected location (docker-compose/init-scripts/initialize.sql
) and contains valid SQL statements for database initialization, including:
- Setting up database configuration
- Creating trigger functions for root user promotion
- Seeding space resources data
- Seeding runtime frameworks data
- Seeding runtime architectures data
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the existence and permissions of the initialization script
# Expected: The script should exist and be readable
# Check if the init-scripts directory exists and contains initialize.sql
fd --type f "initialize.sql" docker-compose/init-scripts
# If found, check its content to ensure it's not empty
if fd --type f "initialize.sql" docker-compose/init-scripts -x cat {}; then
echo "Script exists and has content"
else
echo "Script not found or empty"
fi
Length of output: 13479
-- Fixed frame_npu_image enforce constraint NOT NULL | ||
DO $$ | ||
BEGIN | ||
IF EXISTS ( | ||
SELECT FROM information_schema.columns | ||
WHERE table_name = 'runtime_frameworks' | ||
AND column_name = 'frame_npu_image_01' | ||
) | ||
THEN | ||
ALTER TABLE IF EXISTS runtime_frameworks | ||
ALTER COLUMN frame_npu_image DROP NOT NULL; | ||
END IF; | ||
END | ||
$$; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix column name mismatch in constraint check.
There's a discrepancy between the column being checked (frame_npu_image_01
) and the column being altered (frame_npu_image
).
IF EXISTS (
SELECT FROM information_schema.columns
WHERE table_name = 'runtime_frameworks'
- AND column_name = 'frame_npu_image_01'
+ AND column_name = 'frame_npu_image'
)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
-- Fixed frame_npu_image enforce constraint NOT NULL | |
DO $$ | |
BEGIN | |
IF EXISTS ( | |
SELECT FROM information_schema.columns | |
WHERE table_name = 'runtime_frameworks' | |
AND column_name = 'frame_npu_image_01' | |
) | |
THEN | |
ALTER TABLE IF EXISTS runtime_frameworks | |
ALTER COLUMN frame_npu_image DROP NOT NULL; | |
END IF; | |
END | |
$$; | |
-- Fixed frame_npu_image enforce constraint NOT NULL | |
DO $$ | |
BEGIN | |
IF EXISTS ( | |
SELECT FROM information_schema.columns | |
WHERE table_name = 'runtime_frameworks' | |
AND column_name = 'frame_npu_image' | |
) | |
THEN | |
ALTER TABLE IF EXISTS runtime_frameworks | |
ALTER COLUMN frame_npu_image DROP NOT NULL; | |
END IF; | |
END | |
$$; |
-- Create Trigger Function | ||
CREATE OR REPLACE FUNCTION promote_root_to_admin () | ||
RETURNS TRIGGER | ||
AS $$ | ||
BEGIN | ||
IF NEW.username = 'root' THEN | ||
UPDATE public.users | ||
SET role_mask = 'admin' | ||
WHERE username = 'root'; | ||
UPDATE | ||
public.users | ||
SET | ||
role_mask = 'admin' | ||
WHERE | ||
username = 'root'; | ||
|
||
-- After update Drop all | ||
EXECUTE 'DROP TRIGGER IF EXISTS trigger_promote_root_to_admin ON public.users'; | ||
EXECUTE 'DROP FUNCTION IF EXISTS promote_root_to_admin()'; | ||
END IF; | ||
|
||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql VOLATILE; | ||
$$ | ||
LANGUAGE plpgsql | ||
VOLATILE; | ||
|
||
-- Create Trigger | ||
CREATE OR REPLACE TRIGGER trigger_promote_root_to_admin | ||
AFTER INSERT ON public.users | ||
FOR EACH ROW | ||
EXECUTE FUNCTION promote_root_to_admin(); | ||
EXECUTE FUNCTION promote_root_to_admin (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Protect against potential race conditions in admin promotion.
The current implementation might be vulnerable to race conditions if multiple connections attempt to insert a root user simultaneously. Consider adding transaction isolation and locks.
CREATE OR REPLACE FUNCTION promote_root_to_admin ()
RETURNS TRIGGER
AS $$
BEGIN
+ -- Acquire advisory lock to prevent concurrent promotions
+ PERFORM pg_advisory_xact_lock(hashtext('promote_root_to_admin'));
+
IF NEW.username = 'root' THEN
UPDATE
public.users
SET
role_mask = 'admin'
WHERE
- username = 'root';
+ username = 'root'
+ AND role_mask != 'admin'; -- Only update if not already admin
-- After update Drop all
EXECUTE 'DROP TRIGGER IF EXISTS trigger_promote_root_to_admin ON public.users';
EXECUTE 'DROP FUNCTION IF EXISTS promote_root_to_admin()';
END IF;
RETURN NEW;
END;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
-- Create Trigger Function | |
CREATE OR REPLACE FUNCTION promote_root_to_admin () | |
RETURNS TRIGGER | |
AS $$ | |
BEGIN | |
IF NEW.username = 'root' THEN | |
UPDATE public.users | |
SET role_mask = 'admin' | |
WHERE username = 'root'; | |
UPDATE | |
public.users | |
SET | |
role_mask = 'admin' | |
WHERE | |
username = 'root'; | |
-- After update Drop all | |
EXECUTE 'DROP TRIGGER IF EXISTS trigger_promote_root_to_admin ON public.users'; | |
EXECUTE 'DROP FUNCTION IF EXISTS promote_root_to_admin()'; | |
END IF; | |
RETURN NEW; | |
END; | |
$$ LANGUAGE plpgsql VOLATILE; | |
$$ | |
LANGUAGE plpgsql | |
VOLATILE; | |
-- Create Trigger | |
CREATE OR REPLACE TRIGGER trigger_promote_root_to_admin | |
AFTER INSERT ON public.users | |
FOR EACH ROW | |
EXECUTE FUNCTION promote_root_to_admin(); | |
EXECUTE FUNCTION promote_root_to_admin (); | |
-- Create Trigger Function | |
CREATE OR REPLACE FUNCTION promote_root_to_admin () | |
RETURNS TRIGGER | |
AS $$ | |
BEGIN | |
-- Acquire advisory lock to prevent concurrent promotions | |
PERFORM pg_advisory_xact_lock(hashtext('promote_root_to_admin')); | |
IF NEW.username = 'root' THEN | |
UPDATE | |
public.users | |
SET | |
role_mask = 'admin' | |
WHERE | |
username = 'root' | |
AND role_mask != 'admin'; -- Only update if not already admin | |
-- After update Drop all | |
EXECUTE 'DROP TRIGGER IF EXISTS trigger_promote_root_to_admin ON public.users'; | |
EXECUTE 'DROP FUNCTION IF EXISTS promote_root_to_admin()'; | |
END IF; | |
RETURN NEW; | |
END; | |
$$ | |
LANGUAGE plpgsql | |
VOLATILE; | |
-- Create Trigger | |
CREATE OR REPLACE TRIGGER trigger_promote_root_to_admin | |
AFTER INSERT ON public.users | |
FOR EACH ROW | |
EXECUTE FUNCTION promote_root_to_admin (); |
WITH selected_cluster AS ( | ||
SELECT | ||
cluster_id | ||
FROM | ||
public.cluster_infos | ||
LIMIT 1) | ||
INSERT INTO public.space_resources (id, name, resources, cluster_id) | ||
VALUES | ||
(1, 'CPU basic · 0.5 vCPU · 1 GB', '{ "cpu": { "type": "Intel", "num": "0.5" }, "memory": "1Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(2, 'CPU basic · 2 vCPU · 4 GB', '{ "cpu": { "type": "Intel", "num": "2" }, "memory": "4Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(3, 'NVIDIA A10G · 4 vCPU · 16 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(4, 'NVIDIA A10G · 6 vCPU · 32 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "6" }, "memory": "32Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(5, 'NVIDIA A10G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A10", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(6, 'NVIDIA A10G · 4 · 24 vCPU · 96 GB', '{"gpu": { "type": "A10", "num": "4", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "24" }, "memory": "96Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(7, 'NVIDIA A40G · 4 vCPU · 16 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(8, 'NVIDIA A40G · 8 vCPU · 32 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "8" }, "memory": "32Gi" }', ( SELECT cluster_id FROM selected_cluster)), | ||
(9, 'NVIDIA A40G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A40", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', ( SELECT cluster_id FROM selected_cluster)) | ||
ON CONFLICT (id) | ||
DO UPDATE SET | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; | ||
|
||
INSERT INTO space_resources (name, resources, cluster_id) | ||
VALUES | ||
('NVIDIA A10G · 6 vCPU · 32 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "6" }, "memory": "32Gi" }', (SELECT cluster_id FROM public.cluster_infos LIMIT 1)) | ||
ON CONFLICT (name) | ||
DO UPDATE SET | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; | ||
|
||
INSERT INTO space_resources (name, resources, cluster_id) | ||
VALUES | ||
('NVIDIA A10G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A10", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | ||
ON CONFLICT (name) | ||
DO UPDATE SET | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; | ||
|
||
INSERT INTO space_resources (name, resources, cluster_id) | ||
VALUES | ||
('NVIDIA A10G · 4 · 24 vCPU · 96 GB', '{"gpu": { "type": "A10", "num": "4", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "24" }, "memory": "96Gi" }', (SELECT cluster_id FROM public.cluster_infos LIMIT 1)) | ||
ON CONFLICT (name) | ||
DO UPDATE SET | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; | ||
-- for A40 | ||
INSERT INTO space_resources (name, resources, cluster_id) | ||
VALUES | ||
('NVIDIA A40G · 4 vCPU · 16 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | ||
ON CONFLICT (name) | ||
DO UPDATE SET | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; | ||
|
||
INSERT INTO space_resources (name, resources, cluster_id) | ||
VALUES | ||
('NVIDIA A40G · 8 vCPU · 32 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "8" }, "memory": "32Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | ||
ON CONFLICT (name) | ||
DO UPDATE SET | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; | ||
|
||
|
||
INSERT INTO space_resources (name, resources, cluster_id) | ||
VALUES | ||
('NVIDIA A40G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A40", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | ||
ON CONFLICT (name) | ||
DO UPDATE SET | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; | ||
name = EXCLUDED.name, | ||
resources = EXCLUDED.resources, | ||
cluster_id = EXCLUDED.cluster_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance error handling for cluster selection.
The current implementation silently selects the first cluster without validation. This could lead to incorrect resource allocation if multiple clusters exist or none are found.
WITH selected_cluster AS (
SELECT
cluster_id
FROM
public.cluster_infos
- LIMIT 1)
+ LIMIT 1),
+cluster_validation AS (
+ SELECT CASE
+ WHEN NOT EXISTS (SELECT 1 FROM selected_cluster)
+ THEN RAISE EXCEPTION 'No clusters found in cluster_infos'
+ END
+)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
WITH selected_cluster AS ( | |
SELECT | |
cluster_id | |
FROM | |
public.cluster_infos | |
LIMIT 1) | |
INSERT INTO public.space_resources (id, name, resources, cluster_id) | |
VALUES | |
(1, 'CPU basic · 0.5 vCPU · 1 GB', '{ "cpu": { "type": "Intel", "num": "0.5" }, "memory": "1Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(2, 'CPU basic · 2 vCPU · 4 GB', '{ "cpu": { "type": "Intel", "num": "2" }, "memory": "4Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(3, 'NVIDIA A10G · 4 vCPU · 16 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(4, 'NVIDIA A10G · 6 vCPU · 32 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "6" }, "memory": "32Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(5, 'NVIDIA A10G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A10", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(6, 'NVIDIA A10G · 4 · 24 vCPU · 96 GB', '{"gpu": { "type": "A10", "num": "4", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "24" }, "memory": "96Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(7, 'NVIDIA A40G · 4 vCPU · 16 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(8, 'NVIDIA A40G · 8 vCPU · 32 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "8" }, "memory": "32Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(9, 'NVIDIA A40G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A40", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', ( SELECT cluster_id FROM selected_cluster)) | |
ON CONFLICT (id) | |
DO UPDATE SET | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
INSERT INTO space_resources (name, resources, cluster_id) | |
VALUES | |
('NVIDIA A10G · 6 vCPU · 32 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "6" }, "memory": "32Gi" }', (SELECT cluster_id FROM public.cluster_infos LIMIT 1)) | |
ON CONFLICT (name) | |
DO UPDATE SET | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
INSERT INTO space_resources (name, resources, cluster_id) | |
VALUES | |
('NVIDIA A10G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A10", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | |
ON CONFLICT (name) | |
DO UPDATE SET | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
INSERT INTO space_resources (name, resources, cluster_id) | |
VALUES | |
('NVIDIA A10G · 4 · 24 vCPU · 96 GB', '{"gpu": { "type": "A10", "num": "4", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "24" }, "memory": "96Gi" }', (SELECT cluster_id FROM public.cluster_infos LIMIT 1)) | |
ON CONFLICT (name) | |
DO UPDATE SET | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
-- for A40 | |
INSERT INTO space_resources (name, resources, cluster_id) | |
VALUES | |
('NVIDIA A40G · 4 vCPU · 16 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | |
ON CONFLICT (name) | |
DO UPDATE SET | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
INSERT INTO space_resources (name, resources, cluster_id) | |
VALUES | |
('NVIDIA A40G · 8 vCPU · 32 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "8" }, "memory": "32Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | |
ON CONFLICT (name) | |
DO UPDATE SET | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
INSERT INTO space_resources (name, resources, cluster_id) | |
VALUES | |
('NVIDIA A40G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A40", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', (SELECT cluster_id FROM cluster_infos LIMIT 1)) | |
ON CONFLICT (name) | |
DO UPDATE SET | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
name = EXCLUDED.name, | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; | |
WITH selected_cluster AS ( | |
SELECT | |
cluster_id | |
FROM | |
public.cluster_infos | |
LIMIT 1), | |
cluster_validation AS ( | |
SELECT CASE | |
WHEN NOT EXISTS (SELECT 1 FROM selected_cluster) | |
THEN RAISE EXCEPTION 'No clusters found in cluster_infos' | |
END | |
) | |
INSERT INTO public.space_resources (id, name, resources, cluster_id) | |
VALUES | |
(1, 'CPU basic · 0.5 vCPU · 1 GB', '{ "cpu": { "type": "Intel", "num": "0.5" }, "memory": "1Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(2, 'CPU basic · 2 vCPU · 4 GB', '{ "cpu": { "type": "Intel", "num": "2" }, "memory": "4Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(3, 'NVIDIA A10G · 4 vCPU · 16 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(4, 'NVIDIA A10G · 6 vCPU · 32 GB', '{"gpu": { "type": "A10", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "6" }, "memory": "32Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(5, 'NVIDIA A10G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A10", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(6, 'NVIDIA A10G · 4 · 24 vCPU · 96 GB', '{"gpu": { "type": "A10", "num": "4", "resource_name": "nvidia.com/gpu", "labels": { "aliyun.accelerator/nvidia_name": "NVIDIA-A10" } }, "cpu": { "type": "Intel", "num": "24" }, "memory": "96Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(7, 'NVIDIA A40G · 4 vCPU · 16 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "4" }, "memory": "16Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(8, 'NVIDIA A40G · 8 vCPU · 32 GB', '{"gpu": { "type": "A40", "num": "1", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "8" }, "memory": "32Gi" }', ( SELECT cluster_id FROM selected_cluster)), | |
(9, 'NVIDIA A40G · 2 · 12 vCPU · 48 GB', '{"gpu": { "type": "A40", "num": "2", "resource_name": "nvidia.com/gpu", "labels": { "nvidia.com/nvidia_name": "NVIDIA-A40" } }, "cpu": { "type": "Intel", "num": "12" }, "memory": "48Gi" }', ( SELECT cluster_id FROM selected_cluster)) | |
ON CONFLICT (id) | |
DO UPDATE SET | |
name = EXCLUDED.name, | |
resources = EXCLUDED.resources, | |
cluster_id = EXCLUDED.cluster_id; |
The TipsCodeReview Commands (invoked as MR or PR comments)
CodeReview Discussion ChatThere are 2 ways to chat with Starship CodeReview:
Note: Be mindful of the bot's finite context window. CodeReview Documentation and Community
|
1 similar comment
The TipsCodeReview Commands (invoked as MR or PR comments)
CodeReview Discussion ChatThere are 2 ways to chat with Starship CodeReview:
Note: Be mindful of the bot's finite context window. CodeReview Documentation and Community
|
Summary by CodeRabbit
New Features
Bug Fixes
space_resources
,runtime_frameworks
, andruntime_architectures
tables by consolidating multiple insert statements.Documentation