- Add dbGet/dbAll helper functions for database-agnostic queries - Add toDbBool/convertBooleansForDb for boolean type conversion - Add toDbDate/getNow for timestamp type handling - Add generateId that returns UUID for Postgres, nanoid for SQLite - Update all routes to use compatibility helpers - Add normalizeEvent to return clean number types from Postgres decimal - Add formatPrice utility for consistent price display - Add legal pages admin interface with RichTextEditor - Update carousel images - Add drizzle migration files for PostgreSQL
270 lines
8.5 KiB
SQL
270 lines
8.5 KiB
SQL
CREATE TABLE `audit_logs` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`user_id` text,
|
|
`action` text NOT NULL,
|
|
`target` text,
|
|
`target_id` text,
|
|
`details` text,
|
|
`timestamp` text NOT NULL,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `contacts` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text NOT NULL,
|
|
`email` text NOT NULL,
|
|
`message` text NOT NULL,
|
|
`status` text DEFAULT 'new' NOT NULL,
|
|
`created_at` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `email_logs` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`template_id` text,
|
|
`event_id` text,
|
|
`recipient_email` text NOT NULL,
|
|
`recipient_name` text,
|
|
`subject` text NOT NULL,
|
|
`body_html` text,
|
|
`status` text DEFAULT 'pending' NOT NULL,
|
|
`error_message` text,
|
|
`sent_at` text,
|
|
`sent_by` text,
|
|
`created_at` text NOT NULL,
|
|
FOREIGN KEY (`template_id`) REFERENCES `email_templates`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`sent_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `email_settings` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`key` text NOT NULL,
|
|
`value` text NOT NULL,
|
|
`updated_at` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `email_subscribers` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`email` text NOT NULL,
|
|
`name` text,
|
|
`status` text DEFAULT 'active' NOT NULL,
|
|
`created_at` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `email_templates` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text NOT NULL,
|
|
`slug` text NOT NULL,
|
|
`subject` text NOT NULL,
|
|
`subject_es` text,
|
|
`body_html` text NOT NULL,
|
|
`body_html_es` text,
|
|
`body_text` text,
|
|
`body_text_es` text,
|
|
`description` text,
|
|
`variables` text,
|
|
`is_system` integer DEFAULT false NOT NULL,
|
|
`is_active` integer DEFAULT true NOT NULL,
|
|
`created_at` text NOT NULL,
|
|
`updated_at` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `event_payment_overrides` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`event_id` text NOT NULL,
|
|
`tpago_enabled` integer,
|
|
`tpago_link` text,
|
|
`tpago_instructions` text,
|
|
`tpago_instructions_es` text,
|
|
`bank_transfer_enabled` integer,
|
|
`bank_name` text,
|
|
`bank_account_holder` text,
|
|
`bank_account_number` text,
|
|
`bank_alias` text,
|
|
`bank_phone` text,
|
|
`bank_notes` text,
|
|
`bank_notes_es` text,
|
|
`lightning_enabled` integer,
|
|
`cash_enabled` integer,
|
|
`cash_instructions` text,
|
|
`cash_instructions_es` text,
|
|
`created_at` text NOT NULL,
|
|
`updated_at` text NOT NULL,
|
|
FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `events` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`title` text NOT NULL,
|
|
`title_es` text,
|
|
`description` text NOT NULL,
|
|
`description_es` text,
|
|
`start_datetime` text NOT NULL,
|
|
`end_datetime` text,
|
|
`location` text NOT NULL,
|
|
`location_url` text,
|
|
`price` real DEFAULT 0 NOT NULL,
|
|
`currency` text DEFAULT 'PYG' NOT NULL,
|
|
`capacity` integer DEFAULT 50 NOT NULL,
|
|
`status` text DEFAULT 'draft' NOT NULL,
|
|
`banner_url` text,
|
|
`external_booking_enabled` integer DEFAULT false NOT NULL,
|
|
`external_booking_url` text,
|
|
`created_at` text NOT NULL,
|
|
`updated_at` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `invoices` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`payment_id` text NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`invoice_number` text NOT NULL,
|
|
`ruc_number` text,
|
|
`legal_name` text,
|
|
`amount` real NOT NULL,
|
|
`currency` text DEFAULT 'PYG' NOT NULL,
|
|
`pdf_url` text,
|
|
`status` text DEFAULT 'generated' NOT NULL,
|
|
`created_at` text NOT NULL,
|
|
FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `magic_link_tokens` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`token` text NOT NULL,
|
|
`type` text NOT NULL,
|
|
`expires_at` text NOT NULL,
|
|
`used_at` text,
|
|
`created_at` text NOT NULL,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `media` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`file_url` text NOT NULL,
|
|
`type` text NOT NULL,
|
|
`related_id` text,
|
|
`related_type` text,
|
|
`created_at` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `payment_options` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`tpago_enabled` integer DEFAULT false NOT NULL,
|
|
`tpago_link` text,
|
|
`tpago_instructions` text,
|
|
`tpago_instructions_es` text,
|
|
`bank_transfer_enabled` integer DEFAULT false NOT NULL,
|
|
`bank_name` text,
|
|
`bank_account_holder` text,
|
|
`bank_account_number` text,
|
|
`bank_alias` text,
|
|
`bank_phone` text,
|
|
`bank_notes` text,
|
|
`bank_notes_es` text,
|
|
`lightning_enabled` integer DEFAULT true NOT NULL,
|
|
`cash_enabled` integer DEFAULT true NOT NULL,
|
|
`cash_instructions` text,
|
|
`cash_instructions_es` text,
|
|
`allow_duplicate_bookings` integer DEFAULT false NOT NULL,
|
|
`updated_at` text NOT NULL,
|
|
`updated_by` text,
|
|
FOREIGN KEY (`updated_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `payments` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`ticket_id` text NOT NULL,
|
|
`provider` text NOT NULL,
|
|
`amount` real NOT NULL,
|
|
`currency` text DEFAULT 'PYG' NOT NULL,
|
|
`status` text DEFAULT 'pending' NOT NULL,
|
|
`reference` text,
|
|
`user_marked_paid_at` text,
|
|
`paid_at` text,
|
|
`paid_by_admin_id` text,
|
|
`admin_note` text,
|
|
`created_at` text NOT NULL,
|
|
`updated_at` text NOT NULL,
|
|
FOREIGN KEY (`ticket_id`) REFERENCES `tickets`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `site_settings` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`timezone` text DEFAULT 'America/Asuncion' NOT NULL,
|
|
`site_name` text DEFAULT 'Spanglish' NOT NULL,
|
|
`site_description` text,
|
|
`site_description_es` text,
|
|
`contact_email` text,
|
|
`contact_phone` text,
|
|
`facebook_url` text,
|
|
`instagram_url` text,
|
|
`twitter_url` text,
|
|
`linkedin_url` text,
|
|
`maintenance_mode` integer DEFAULT false NOT NULL,
|
|
`maintenance_message` text,
|
|
`maintenance_message_es` text,
|
|
`updated_at` text NOT NULL,
|
|
`updated_by` text,
|
|
FOREIGN KEY (`updated_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `tickets` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`event_id` text NOT NULL,
|
|
`attendee_first_name` text NOT NULL,
|
|
`attendee_last_name` text,
|
|
`attendee_email` text,
|
|
`attendee_phone` text,
|
|
`attendee_ruc` text,
|
|
`preferred_language` text,
|
|
`status` text DEFAULT 'pending' NOT NULL,
|
|
`checkin_at` text,
|
|
`checked_in_by_admin_id` text,
|
|
`qr_code` text,
|
|
`admin_note` text,
|
|
`created_at` text NOT NULL,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`checked_in_by_admin_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `user_sessions` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`token` text NOT NULL,
|
|
`user_agent` text,
|
|
`ip_address` text,
|
|
`last_active_at` text NOT NULL,
|
|
`expires_at` text NOT NULL,
|
|
`created_at` text NOT NULL,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `users` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`email` text NOT NULL,
|
|
`password` text,
|
|
`name` text NOT NULL,
|
|
`phone` text,
|
|
`role` text DEFAULT 'user' NOT NULL,
|
|
`language_preference` text,
|
|
`is_claimed` integer DEFAULT true NOT NULL,
|
|
`google_id` text,
|
|
`ruc_number` text,
|
|
`account_status` text DEFAULT 'active' NOT NULL,
|
|
`created_at` text NOT NULL,
|
|
`updated_at` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `email_settings_key_unique` ON `email_settings` (`key`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `email_subscribers_email_unique` ON `email_subscribers` (`email`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `email_templates_name_unique` ON `email_templates` (`name`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `email_templates_slug_unique` ON `email_templates` (`slug`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `invoices_invoice_number_unique` ON `invoices` (`invoice_number`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `magic_link_tokens_token_unique` ON `magic_link_tokens` (`token`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `user_sessions_token_unique` ON `user_sessions` (`token`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`); |