diff --git a/.gitignore b/.gitignore index 80ec311..b9e1aec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ node_modules /.cache /build .env +package-lock.json +yarn.lock +pnpm-lock.yaml diff --git a/app/data/liveness.db b/app/data/liveness.db deleted file mode 100644 index e69de29..0000000 diff --git a/app/db/config.server.ts b/app/db/config.server.ts index 013453b..67f5a9f 100644 --- a/app/db/config.server.ts +++ b/app/db/config.server.ts @@ -1,7 +1,10 @@ -import { drizzle } from 'drizzle-orm/better-sqlite3'; -import Database from 'better-sqlite3'; -import * as schema from './schema'; // Aquí irán tus modelos definidos +import { drizzle } from 'drizzle-orm/vercel-postgres'; +import {sql} from '@vercel/postgres' +import * as schema from './schema'; +import {config} from 'dotenv'; -// Conexión a la base de datos SQLite -const sqlite = new Database('data/liveness.db'); // Asegúrate de que esta ruta sea correcta -export const db = drizzle(sqlite, { schema }); +config({ + path:'.env' +}); + +export const db = drizzle(sql, { schema }); diff --git a/app/db/helpers.ts b/app/db/helpers.ts index bf0d1b1..bed1775 100644 --- a/app/db/helpers.ts +++ b/app/db/helpers.ts @@ -1,14 +1,14 @@ import { db } from "./config.server"; -import { liveness, users } from "./schema"; +import { liveness, liveness_results, users } from "./schema"; import { v4 as uuid } from 'uuid'; -import { User } from "../types/settings"; +import { Liveness, LivenessResult, User } from "../types/settings"; import {sql,eq} from 'drizzle-orm' -//Obtener usuarios +//GET export const getAllUsers = () => { - db.select().from(users).all(); + db.select().from(users) return { status: 'OK', status_code: 200, @@ -17,7 +17,7 @@ export const getAllUsers = () => { }; export const getUserWithLiveness = (userId: string) => { - const userWithLiveness = db.select().from(users).leftJoin(liveness, eq(liveness.id_user , users.id)).where(sql`${users.id} = ${userId}`).all(); + const userWithLiveness = db.select().from(users).leftJoin(liveness, eq(liveness.id_user , users.id)).where(sql`${users.id} = ${userId}`); return { status: 'OK', @@ -26,6 +26,25 @@ export const getUserWithLiveness = (userId: string) => { } } +export const getUserById = async (id:string) => { + const user = await db.select().from(users).where(sql`${users.id} = ${id}`); + return { + status: 'OK', + status_code: 200, + data: JSON.stringify(user), + }; +}; + +export const getLivenessById = async (id:string) => { + const liveness = await db.select().from(liveness_results).where(sql`${liveness_results.id} = ${id}`); + return { + status: 'OK', + status_code: 200, + data: JSON.stringify(liveness), + }; +}; + +//POST export const addNewUser = async (data:User) => { const newUser = { id: uuid(), @@ -40,6 +59,7 @@ export const addNewUser = async (data:User) => { country: data.country, email: data.email, password: data.password, + serial_number: data.serial_number, }; await db.insert(users).values(newUser); @@ -51,11 +71,40 @@ export const addNewUser = async (data:User) => { }; }; -export const getUserById = async (id:string) => { - const user = await db.select().from(users).where(sql`${users.id} = ${id}`).all(); +export const addNewLiveness = async (data:Liveness) => { + const newLiveness = { + id: uuid(), + id_user: data.id_user, + start_date: data.start_date, + end_date: data.end_date, + result: data.result, + ip_address: data.ip_address, + token_session: data.token_session, + device_info: data.device_info, + }; + await db.insert(liveness).values(newLiveness); return { status: 'OK', - status_code: 200, - data: JSON.stringify(user), + status_code: 201, + message: 'Liveness created correctly', + data: JSON.stringify(newLiveness), }; -}; \ No newline at end of file +}; + +export const addNewLivenessResult = async (data:LivenessResult) => { + const newLivenessResult = { + id: uuid(), + id_liveness: data.id_liveness, + action_type: data.action_type, + action_result: data.action_result, + }; + await db.insert(liveness_results).values(newLivenessResult); + return { + status: 'OK', + status_code: 201, + message: 'Liveness result created correctly', + data: JSON.stringify(newLivenessResult), + }; +}; + + diff --git a/app/db/schema.ts b/app/db/schema.ts index e99eacf..5027e21 100644 --- a/app/db/schema.ts +++ b/app/db/schema.ts @@ -1,35 +1,66 @@ // db/schema.ts -import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'; -import {sql} from 'drizzle-orm'; +import { + pgTable, + text, + boolean, + timestamp , + uniqueIndex, +} from "drizzle-orm/pg-core"; -export const users = sqliteTable('users', { - id: text('id').primaryKey(), - document_number: text('document_number').notNull(), - name: text('name').notNull(), - lastName: text('lastName').notNull(), - surName: text('surName').notNull(), - birthDate: integer('birthDate' , {mode:'timestamp'}).notNull(), - gender: text('gender').notNull(), - phone: text('phone').notNull(), - register_date: integer("register_date",{mode:'timestamp_ms'}).default(sql`datetime('now')`).notNull(), - country: text('country').notNull(), - email: text('email').notNull(), - password: text('password').notNull(), -}); +export const users = pgTable( + "users", + { + id: text("id").primaryKey(), + document_number: text("document_number").notNull(), + name: text("name").notNull(), + lastName: text("lastName").notNull(), + surName: text("surName").notNull(), + birthDate: timestamp("birthDate" ,{withTimezone: true}).notNull(), + gender: text("gender").notNull(), + phone: text("phone").notNull(), + serial_number: text("serial_number").notNull(), + register_date: timestamp("register_date").defaultNow().notNull(), + country: text("country").notNull(), + email: text("email").notNull(), + password: text("password").notNull(), + }, + (users) => { + return { + uniqueIdx: uniqueIndex("unique_idx").on( + users.document_number, + users.email, + users.serial_number + ), + }; + } +); -export const liveness = sqliteTable('liveness', { - id: text('id').primaryKey(), - id_user: text('id_user').notNull().references(() => users.id), - start_date: integer('start_date',{mode:'timestamp_ms'}).notNull(), - end_date: integer('end_date',{mode:'timestamp_ms'}).notNull(), - result: integer('result',{mode:'boolean'}).notNull(), - ip_address: text('ip_address').notNull(), - device_info: text('device_info').notNull(), -}); +export const liveness = pgTable( + "liveness", + { + id: text("id").primaryKey(), + id_user: text("id_user") + .notNull() + .references(() => users.id), + initialDate: timestamp("initialDate", {withTimezone: true}).notNull(), + finishDate: timestamp("finishDate", {withTimezone: true}).notNull(), + result: boolean("result").notNull(), + ip_address: text("ip_address").notNull(), + token_session: text("token_session").notNull(), + device_info: text("device_info").notNull(), + }, + (liveness) => { + return { + uniqueToken: uniqueIndex("unique_token").on(liveness.token_session), + }; + } +); -export const liveness_results = sqliteTable('liveness_results', { - id: text('id').primaryKey(), - id_liveness: text('id_liveness').notNull().references(() => liveness.id), - action_type: text('action_type').notNull(), - action_result: integer('action_result',{mode:'boolean'}).notNull(), +export const liveness_results = pgTable("liveness_results", { + id: text("id").primaryKey(), + id_liveness: text("id_liveness") + .notNull() + .references(() => liveness.id), + action_type: text("action_type").notNull(), + action_result: boolean("action_result").notNull(), }); diff --git a/app/types/settings.ts b/app/types/settings.ts index 6bae606..0765aba 100644 --- a/app/types/settings.ts +++ b/app/types/settings.ts @@ -13,4 +13,23 @@ export type User = { country: string; email: string; password: string; + serial_number: string; +}; + +export type Liveness = { + id?: string; + id_user: string; + start_date: Date; + end_date: Date; + result: boolean; + ip_address: string; + token_session: string; + device_info: string; +}; + +export type LivenessResult = { + id?: string; + id_liveness: string; + action_type: string; + action_result: boolean; }; \ No newline at end of file diff --git a/drizzle.config.ts b/drizzle.config.ts index 076e48d..09c9fed 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -1,10 +1,13 @@ -import { defineConfig } from "drizzle-kit"; +import { config } from 'dotenv'; +import { defineConfig } from 'drizzle-kit'; + +config({ path: '.env.local' }); export default defineConfig({ - schema:'./app/db/schema.ts', - output: './app/db/migrations', - dialect: 'sqlite', - dbCredentials:{ - - } + schema: './app/db/schema.ts', + out: './migrations', + dialect: 'postgresql', + dbCredentials: { + url: process.env.POSTGRES_URL!, + }, }); \ No newline at end of file diff --git a/migrations/0002_flawless_kinsey_walden.sql b/migrations/0002_flawless_kinsey_walden.sql new file mode 100644 index 0000000..739c6c9 --- /dev/null +++ b/migrations/0002_flawless_kinsey_walden.sql @@ -0,0 +1,4 @@ +SET timezone = 'America/Santiago'; +ALTER TABLE "liveness" ALTER COLUMN "initialDate" SET DATA TYPE timestamp with time zone;--> statement-breakpoint +ALTER TABLE "liveness" ALTER COLUMN "finishDate" SET DATA TYPE timestamp with time zone;--> statement-breakpoint +ALTER TABLE "users" ALTER COLUMN "birthDate" SET DATA TYPE timestamp with time zone; \ No newline at end of file diff --git a/migrations/0003_aspiring_energizer.sql b/migrations/0003_aspiring_energizer.sql new file mode 100644 index 0000000..d1cabb2 --- /dev/null +++ b/migrations/0003_aspiring_energizer.sql @@ -0,0 +1 @@ +ALTER TABLE "liveness" ALTER COLUMN "finishDate" DROP DEFAULT; \ No newline at end of file diff --git a/migrations/meta/0000_snapshot.json b/migrations/meta/0000_snapshot.json new file mode 100644 index 0000000..0c9c646 --- /dev/null +++ b/migrations/meta/0000_snapshot.json @@ -0,0 +1,270 @@ +{ + "id": "61fc02f1-1dd7-4774-a5e7-14d6b490c5ab", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.liveness": { + "name": "liveness", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_user": { + "name": "id_user", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "initialDate": { + "name": "initialDate", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "finishDate": { + "name": "finishDate", + "type": "date", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "result": { + "name": "result", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_session": { + "name": "token_session", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "device_info": { + "name": "device_info", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_token": { + "name": "unique_token", + "columns": [ + { + "expression": "token_session", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "liveness_id_user_users_id_fk": { + "name": "liveness_id_user_users_id_fk", + "tableFrom": "liveness", + "tableTo": "users", + "columnsFrom": [ + "id_user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.liveness_results": { + "name": "liveness_results", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_liveness": { + "name": "id_liveness", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_result": { + "name": "action_result", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "liveness_results_id_liveness_liveness_id_fk": { + "name": "liveness_results_id_liveness_liveness_id_fk", + "tableFrom": "liveness_results", + "tableTo": "liveness", + "columnsFrom": [ + "id_liveness" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "document_number": { + "name": "document_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "surName": { + "name": "surName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "birthDate": { + "name": "birthDate", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "gender": { + "name": "gender", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "serial_number": { + "name": "serial_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "register_date": { + "name": "register_date", + "type": "date", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_idx": { + "name": "unique_idx", + "columns": [ + { + "expression": "document_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "serial_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/0001_snapshot.json b/migrations/meta/0001_snapshot.json new file mode 100644 index 0000000..32540c6 --- /dev/null +++ b/migrations/meta/0001_snapshot.json @@ -0,0 +1,270 @@ +{ + "id": "79c24c95-4b4b-4394-b90f-3a0f40a047fa", + "prevId": "61fc02f1-1dd7-4774-a5e7-14d6b490c5ab", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.liveness": { + "name": "liveness", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_user": { + "name": "id_user", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "initialDate": { + "name": "initialDate", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "finishDate": { + "name": "finishDate", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "result": { + "name": "result", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_session": { + "name": "token_session", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "device_info": { + "name": "device_info", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_token": { + "name": "unique_token", + "columns": [ + { + "expression": "token_session", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "liveness_id_user_users_id_fk": { + "name": "liveness_id_user_users_id_fk", + "tableFrom": "liveness", + "tableTo": "users", + "columnsFrom": [ + "id_user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.liveness_results": { + "name": "liveness_results", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_liveness": { + "name": "id_liveness", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_result": { + "name": "action_result", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "liveness_results_id_liveness_liveness_id_fk": { + "name": "liveness_results_id_liveness_liveness_id_fk", + "tableFrom": "liveness_results", + "tableTo": "liveness", + "columnsFrom": [ + "id_liveness" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "document_number": { + "name": "document_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "surName": { + "name": "surName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "birthDate": { + "name": "birthDate", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "gender": { + "name": "gender", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "serial_number": { + "name": "serial_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "register_date": { + "name": "register_date", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_idx": { + "name": "unique_idx", + "columns": [ + { + "expression": "document_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "serial_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/0002_snapshot.json b/migrations/meta/0002_snapshot.json new file mode 100644 index 0000000..c960667 --- /dev/null +++ b/migrations/meta/0002_snapshot.json @@ -0,0 +1,270 @@ +{ + "id": "e75e63a0-1b5a-428b-b9b2-32ff32bbfbc9", + "prevId": "79c24c95-4b4b-4394-b90f-3a0f40a047fa", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.liveness": { + "name": "liveness", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_user": { + "name": "id_user", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "initialDate": { + "name": "initialDate", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "finishDate": { + "name": "finishDate", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "result": { + "name": "result", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_session": { + "name": "token_session", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "device_info": { + "name": "device_info", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_token": { + "name": "unique_token", + "columns": [ + { + "expression": "token_session", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "liveness_id_user_users_id_fk": { + "name": "liveness_id_user_users_id_fk", + "tableFrom": "liveness", + "tableTo": "users", + "columnsFrom": [ + "id_user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.liveness_results": { + "name": "liveness_results", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_liveness": { + "name": "id_liveness", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_result": { + "name": "action_result", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "liveness_results_id_liveness_liveness_id_fk": { + "name": "liveness_results_id_liveness_liveness_id_fk", + "tableFrom": "liveness_results", + "tableTo": "liveness", + "columnsFrom": [ + "id_liveness" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "document_number": { + "name": "document_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "surName": { + "name": "surName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "birthDate": { + "name": "birthDate", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "gender": { + "name": "gender", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "serial_number": { + "name": "serial_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "register_date": { + "name": "register_date", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_idx": { + "name": "unique_idx", + "columns": [ + { + "expression": "document_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "serial_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/0003_snapshot.json b/migrations/meta/0003_snapshot.json new file mode 100644 index 0000000..4f266ba --- /dev/null +++ b/migrations/meta/0003_snapshot.json @@ -0,0 +1,269 @@ +{ + "id": "f0f532cb-c8f4-4443-9079-56757bcac12d", + "prevId": "e75e63a0-1b5a-428b-b9b2-32ff32bbfbc9", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.liveness": { + "name": "liveness", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_user": { + "name": "id_user", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "initialDate": { + "name": "initialDate", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "finishDate": { + "name": "finishDate", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "result": { + "name": "result", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_session": { + "name": "token_session", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "device_info": { + "name": "device_info", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_token": { + "name": "unique_token", + "columns": [ + { + "expression": "token_session", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "liveness_id_user_users_id_fk": { + "name": "liveness_id_user_users_id_fk", + "tableFrom": "liveness", + "tableTo": "users", + "columnsFrom": [ + "id_user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.liveness_results": { + "name": "liveness_results", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "id_liveness": { + "name": "id_liveness", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_type": { + "name": "action_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action_result": { + "name": "action_result", + "type": "boolean", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "liveness_results_id_liveness_liveness_id_fk": { + "name": "liveness_results_id_liveness_liveness_id_fk", + "tableFrom": "liveness_results", + "tableTo": "liveness", + "columnsFrom": [ + "id_liveness" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "document_number": { + "name": "document_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "surName": { + "name": "surName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "birthDate": { + "name": "birthDate", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "gender": { + "name": "gender", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "serial_number": { + "name": "serial_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "register_date": { + "name": "register_date", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "unique_idx": { + "name": "unique_idx", + "columns": [ + { + "expression": "document_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "serial_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json new file mode 100644 index 0000000..aa94b6c --- /dev/null +++ b/migrations/meta/_journal.json @@ -0,0 +1,34 @@ +{ + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1728160110359, + "tag": "0000_smooth_zarda", + "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1728160374580, + "tag": "0001_reflective_spiral", + "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1728160619657, + "tag": "0002_flawless_kinsey_walden", + "breakpoints": true + }, + { + "idx": 3, + "version": "7", + "when": 1728160793695, + "tag": "0003_aspiring_energizer", + "breakpoints": true + } + ] +} \ No newline at end of file