mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-06-04 12:33:01 +00:00
82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: bootstrap.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const bootstrapOrganization = `-- name: BootstrapOrganization :one
|
|
WITH new_org AS (
|
|
INSERT INTO core.organizations (slug, name)
|
|
VALUES ($1, $2)
|
|
RETURNING id, slug, name, created_at
|
|
),
|
|
new_org_member AS (
|
|
INSERT INTO core.organization_members (organization_id, user_id, role)
|
|
SELECT id, $3, 'owner'::core.org_role FROM new_org
|
|
),
|
|
new_project AS (
|
|
INSERT INTO core.projects (organization_id, slug, name, description)
|
|
SELECT id, $4, $5, $6 FROM new_org
|
|
RETURNING id, organization_id, slug, name, description, created_at
|
|
),
|
|
new_project_member AS (
|
|
INSERT INTO core.project_members (project_id, user_id, role)
|
|
SELECT id, $3, 'admin'::core.project_role FROM new_project
|
|
)
|
|
SELECT
|
|
new_org.id AS organization_id,
|
|
new_org.slug AS organization_slug,
|
|
new_org.name AS organization_name,
|
|
new_project.id AS project_id,
|
|
new_project.slug AS project_slug,
|
|
new_project.name AS project_name
|
|
FROM new_org
|
|
JOIN new_project ON TRUE
|
|
`
|
|
|
|
type BootstrapOrganizationParams struct {
|
|
Slug string `json:"slug"`
|
|
Name string `json:"name"`
|
|
UserID uuid.UUID `json:"user_id"`
|
|
Slug_2 string `json:"slug_2"`
|
|
Name_2 string `json:"name_2"`
|
|
Description *string `json:"description"`
|
|
}
|
|
|
|
type BootstrapOrganizationRow struct {
|
|
OrganizationID uuid.UUID `json:"organization_id"`
|
|
OrganizationSlug string `json:"organization_slug"`
|
|
OrganizationName string `json:"organization_name"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
ProjectSlug string `json:"project_slug"`
|
|
ProjectName string `json:"project_name"`
|
|
}
|
|
|
|
func (q *Queries) BootstrapOrganization(ctx context.Context, arg BootstrapOrganizationParams) (BootstrapOrganizationRow, error) {
|
|
row := q.db.QueryRow(ctx, bootstrapOrganization,
|
|
arg.Slug,
|
|
arg.Name,
|
|
arg.UserID,
|
|
arg.Slug_2,
|
|
arg.Name_2,
|
|
arg.Description,
|
|
)
|
|
var i BootstrapOrganizationRow
|
|
err := row.Scan(
|
|
&i.OrganizationID,
|
|
&i.OrganizationSlug,
|
|
&i.OrganizationName,
|
|
&i.ProjectID,
|
|
&i.ProjectSlug,
|
|
&i.ProjectName,
|
|
)
|
|
return i, err
|
|
}
|