refactor: move sqlc files into internal/db/sqlc directory

This commit is contained in:
2026-05-01 12:54:36 +07:00
parent 3185dd09f3
commit e863bc7f10
9 changed files with 1 additions and 0 deletions
@@ -0,0 +1,10 @@
DROP TABLE IF EXISTS public.verification;
DROP TABLE IF EXISTS public.jwks;
DROP TABLE IF EXISTS public.session;
DROP TABLE IF EXISTS public.account;
DROP TABLE IF EXISTS public."user";
DROP TABLE IF EXISTS drizzle.__drizzle_migrations;
DROP SCHEMA IF EXISTS drizzle;
DROP EXTENSION IF EXISTS pgcrypto;
@@ -0,0 +1,88 @@
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE public."user" (
id TEXT PRIMARY KEY,
ssh_identifier TEXT NOT NULL DEFAULT substr(encode(gen_random_bytes(16), 'hex'), 1, 32),
name TEXT NOT NULL,
email TEXT NOT NULL,
email_verified BOOLEAN NOT NULL DEFAULT false,
image TEXT,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX user_email_unique
ON public."user"(email);
CREATE UNIQUE INDEX user_ssh_identifier_unique
ON public."user"(ssh_identifier);
CREATE TABLE public.account (
id TEXT PRIMARY KEY,
account_id TEXT NOT NULL,
provider_id TEXT NOT NULL,
user_id TEXT NOT NULL,
access_token TEXT,
refresh_token TEXT,
id_token TEXT,
access_token_expires_at TIMESTAMP WITHOUT TIME ZONE,
refresh_token_expires_at TIMESTAMP WITHOUT TIME ZONE,
scope TEXT,
password TEXT,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL
);
CREATE INDEX account_userId_idx
ON public.account(user_id);
ALTER TABLE public.account
ADD CONSTRAINT account_user_id_user_id_fk
FOREIGN KEY (user_id)
REFERENCES public."user"(id)
ON DELETE CASCADE;
CREATE TABLE public.session (
id TEXT PRIMARY KEY,
expires_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
token TEXT NOT NULL,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
ip_address TEXT,
user_agent TEXT,
user_id TEXT NOT NULL
);
CREATE UNIQUE INDEX session_token_unique
ON public.session(token);
CREATE INDEX session_userId_idx
ON public.session(user_id);
ALTER TABLE public.session
ADD CONSTRAINT session_user_id_user_id_fk
FOREIGN KEY (user_id)
REFERENCES public."user"(id)
ON DELETE CASCADE;
CREATE TABLE public.jwks (
id TEXT PRIMARY KEY,
public_key TEXT NOT NULL,
private_key TEXT NOT NULL,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
expires_at TIMESTAMP WITHOUT TIME ZONE
);
CREATE TABLE public.verification (
id TEXT PRIMARY KEY,
identifier TEXT NOT NULL,
value TEXT NOT NULL,
expires_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
);
CREATE INDEX verification_identifier_idx
ON public.verification(identifier);
+5
View File
@@ -0,0 +1,5 @@
-- name: GetVerifiedEmailBySSHIdentifier :one
SELECT email
FROM public."user"
WHERE ssh_identifier = $1
AND email_verified = true;
+32
View File
@@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
package repository
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}
+56
View File
@@ -0,0 +1,56 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
package repository
import (
"github.com/jackc/pgx/v5/pgtype"
)
type Account struct {
ID string
AccountID string
ProviderID string
UserID string
AccessToken pgtype.Text
RefreshToken pgtype.Text
IDToken pgtype.Text
AccessTokenExpiresAt pgtype.Timestamp
RefreshTokenExpiresAt pgtype.Timestamp
Scope pgtype.Text
Password pgtype.Text
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
}
type Session struct {
ID string
ExpiresAt pgtype.Timestamp
Token string
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
IpAddress pgtype.Text
UserAgent pgtype.Text
UserID string
}
type User struct {
ID string
SshIdentifier string
Name string
Email string
EmailVerified bool
Image pgtype.Text
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
}
type Verification struct {
ID string
Identifier string
Value string
ExpiresAt pgtype.Timestamp
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
}
+24
View File
@@ -0,0 +1,24 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: query.sql
package repository
import (
"context"
)
const getVerifiedEmailBySSHIdentifier = `-- name: GetVerifiedEmailBySSHIdentifier :one
SELECT email
FROM public."user"
WHERE ssh_identifier = $1
AND email_verified = true
`
func (q *Queries) GetVerifiedEmailBySSHIdentifier(ctx context.Context, sshIdentifier string) (string, error) {
row := q.db.QueryRow(ctx, getVerifiedEmailBySSHIdentifier, sshIdentifier)
var email string
err := row.Scan(&email)
return email, err
}
+26
View File
@@ -0,0 +1,26 @@
version: "2"
sql:
- engine: "postgresql"
queries: "queries"
schema: "migrations"
gen:
go:
package: "repository"
out: "repository"
sql_package: "pgx/v5"
overrides:
- db_type: "uuid"
go_type:
import: "github.com/google/uuid"
type: "UUID"
- db_type: "uuid"
go_type:
import: "github.com/google/uuid"
type: "UUID"
pointer: true
nullable: true
- db_type: "timestamptz"
go_type:
type: "*time.Time"
pointer: true
nullable: true