forked from varti-alma/av-idea-millonaria
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,279 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ node_modules | |
/.cache | ||
/build | ||
.env | ||
package-lock.json | ||
yarn.lock | ||
pnpm-lock.yaml |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE "liveness" ALTER COLUMN "finishDate" DROP DEFAULT; |
Oops, something went wrong.