common/dal/schema/000018_init.up.sql
skeris 8b01e8e76f Merge branch 'imp'
Conflicts:
	dal/dal.go
	dal/db_query/queries.sql
	dal/schema/000017_init.down.sql
	dal/schema/000017_init.up.sql
	dal/schema/000018_init.down.sql
	dal/schema/000018_init.up.sql
	dal/sqlcgen/models.go
	dal/sqlcgen/queries.sql.go
	go.mod
	model/model.go
	repository/account/account.go
	repository/question/question.go
	repository/quiz/quiz.go
	repository/result/result.go
	sqlc.yaml
2025-05-14 01:38:55 +03:00

30 lines
968 B
SQL

CREATE TABLE IF NOT EXISTS gigachatAudience (
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
QuizID BIGINT NOT NULL,
Sex BOOLEAN NOT NULL,
Age VARCHAR(5) NOT NULL,
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_quiz FOREIGN KEY (QuizID) REFERENCES quiz(ID)
);
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'tgAccountStatus') THEN
CREATE TYPE TgAccountStatus AS ENUM ('active', 'inactive', 'ban');
END IF;
END $$;
CREATE TABLE IF NOT EXISTS tgAccounts (
id bigserial primary key ,
ApiID integer not null,
ApiHash text not null ,
PhoneNumber text not null ,
Password text not null ,
Status TgAccountStatus not null,
Deleted bool not null default false,
CreatedAt timestamp not null default current_timestamp
);
CREATE UNIQUE INDEX idx_apiid_apihash ON tgAccounts (ApiID, ApiHash) WHERE Deleted = false;