WITH "created" AS (
    INSERT INTO "users" (
                 "email",
                 "full_name",
                 "active")
         VALUES (:'email',
                 'Initial User',
                 TRUE)
    RETURNING "id"
),
     "roles" AS (
    INSERT INTO "user_roles" ("user_id", "role_name")
    SELECT "id", 'admin'
      FROM "created"
)
INSERT INTO "user_tokens" ("user_id", "token")
SELECT "id", (SELECT string_agg (substr (c, (random() * length (c) + 1)::integer, 1), '') AS "token"
                FROM (VALUES ('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')) AS x(c),
                     generate_series (1, 32))
  FROM "created"
RETURNING 'https://example.com/auth/password/' || "token" AS "Password URL"
