mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
POST /projects/:id/import-compose deploys a compose file straight into a project — no template row required. Well-known DB images become managed databases attached to the project network under their service name as DNS alias; other services deploy in dependency order via deployTemplateGraph. - api: extract composeToSpecs converter (shared by the template import-compose preview and the new project endpoint); fix dropped env warnings (pointer receiver); replace insertion sort with sort.Strings - cascade: database_services.project_id links graph-provisioned DBs to their project so project delete tears down runtime + row (previously leaked container + network) - cli: new `containr import` group, `import compose <project> <file|->` - mcp: containr_projects_import_compose tool - openapi + regenerated frontend types; docs snapshot + CLI.md - frontend: compose import modal on the project workspace toolbar - tests: composeToSpecs conversion, ordering, db-image map, warnings
134 lines
4.1 KiB
SQL
134 lines
4.1 KiB
SQL
-- name: ListDatabaseServicesByUser :many
|
|
SELECT database_services.*
|
|
FROM database_services
|
|
WHERE user_id = $1
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: ListAllDatabaseServices :many
|
|
SELECT database_services.*
|
|
FROM database_services
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: GetDatabaseServiceByID :one
|
|
SELECT database_services.*
|
|
FROM database_services
|
|
WHERE id = $1;
|
|
|
|
-- name: GetDatabaseServiceOwnerID :one
|
|
SELECT user_id
|
|
FROM database_services
|
|
WHERE id = $1;
|
|
|
|
-- name: GetDatabaseServiceByIDAndUser :one
|
|
SELECT database_services.*
|
|
FROM database_services
|
|
WHERE id = $1 AND user_id = $2;
|
|
|
|
-- name: DatabaseServiceExistsByIDAndUser :one
|
|
SELECT EXISTS(
|
|
SELECT 1 FROM database_services WHERE id = $1 AND user_id = $2
|
|
);
|
|
|
|
-- name: CountDatabaseServicesByUserAndName :one
|
|
SELECT COUNT(*)
|
|
FROM database_services
|
|
WHERE user_id = sqlc.arg(user_id) AND LOWER(name) = LOWER(sqlc.arg(name));
|
|
|
|
-- name: CreateDatabaseService :exec
|
|
INSERT INTO database_services (id, user_id, name, type, status, version, plan, region, public_port, project_id, created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);
|
|
|
|
-- name: ListDatabaseServicesByProject :many
|
|
SELECT database_services.*
|
|
FROM database_services
|
|
WHERE project_id = $1
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: DeleteDatabaseServiceByID :exec
|
|
DELETE FROM database_services
|
|
WHERE id = $1;
|
|
|
|
-- name: SetDatabaseServicePublicPortByIDAndUser :exec
|
|
UPDATE database_services
|
|
SET public_port = $1, updated_at = $2
|
|
WHERE id = $3 AND user_id = $4;
|
|
|
|
-- name: UpdateDatabaseServiceNameAndPlanByIDAndUser :exec
|
|
UPDATE database_services
|
|
SET name = $1, plan = $2, updated_at = $3
|
|
WHERE id = $4 AND user_id = $5;
|
|
|
|
-- name: UpdateDatabaseServiceNameByIDAndUser :exec
|
|
UPDATE database_services
|
|
SET name = $1, updated_at = $2
|
|
WHERE id = $3 AND user_id = $4;
|
|
|
|
-- name: UpdateDatabaseServicePlanByIDAndUser :exec
|
|
UPDATE database_services
|
|
SET plan = $1, updated_at = $2
|
|
WHERE id = $3 AND user_id = $4;
|
|
|
|
-- name: DeleteDatabaseServiceByIDAndUser :exec
|
|
DELETE FROM database_services
|
|
WHERE id = $1 AND user_id = $2;
|
|
|
|
-- name: SetDatabaseServiceStatusByIDAndUser :exec
|
|
UPDATE database_services
|
|
SET status = $1, updated_at = $2
|
|
WHERE id = $3 AND user_id = $4;
|
|
|
|
-- name: SetDatabaseServiceStatusByID :exec
|
|
UPDATE database_services
|
|
SET status = $1, updated_at = $2
|
|
WHERE id = $3;
|
|
|
|
-- name: SetDatabaseServiceStatusAndConnectionByID :exec
|
|
UPDATE database_services
|
|
SET status = $1, connection_url = $2, updated_at = $3
|
|
WHERE id = $4;
|
|
|
|
-- name: ListDatabaseBackupsByDatabaseAndUser :many
|
|
SELECT b.id, b.database_id, b.size, b.status, b.backup_path, b.remote_key, b.created_at, b.completed_at
|
|
FROM database_backups b
|
|
JOIN database_services s ON s.id = b.database_id
|
|
WHERE b.database_id = $1 AND s.user_id = $2
|
|
ORDER BY b.created_at DESC
|
|
LIMIT $3;
|
|
|
|
-- name: GetDatabaseBackupByIDAndDatabaseAndUser :one
|
|
SELECT b.id, b.database_id, b.size, b.status, b.backup_path, b.remote_key, b.created_at, b.completed_at
|
|
FROM database_backups b
|
|
JOIN database_services s ON s.id = b.database_id
|
|
WHERE b.id = $1 AND b.database_id = $2 AND s.user_id = $3;
|
|
|
|
-- name: CreateDatabaseBackup :exec
|
|
INSERT INTO database_backups (id, database_id, size, status, backup_path, created_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6);
|
|
|
|
-- name: SetDatabaseBackupStatusByID :exec
|
|
UPDATE database_backups
|
|
SET status = $1, size = $2, completed_at = $3
|
|
WHERE id = $4;
|
|
|
|
-- name: SetDatabaseBackupScheduleByIDAndUser :exec
|
|
UPDATE database_services
|
|
SET backup_schedule = $1, next_backup_at = $2, updated_at = $3
|
|
WHERE id = $4 AND user_id = $5;
|
|
|
|
-- name: ListDueDatabaseBackups :many
|
|
SELECT id, backup_schedule
|
|
FROM database_services
|
|
WHERE backup_schedule IS NOT NULL AND backup_schedule <> ''
|
|
AND next_backup_at IS NOT NULL AND next_backup_at <= NOW();
|
|
|
|
-- name: SetDatabaseNextBackupAt :exec
|
|
UPDATE database_services
|
|
SET next_backup_at = $1
|
|
WHERE id = $2;
|
|
|
|
-- name: CreateExternalDatabaseService :exec
|
|
INSERT INTO database_services (id, user_id, name, type, status, version, plan, region,
|
|
provider, external_host, external_port, external_name, external_username, external_password, external_ssl,
|
|
created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, 'running', $5, $6, $7, 'external', $8, $9, $10, $11, $12, $13, $14, $15);
|