mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-22 14:16:19 +00:00
usar drizzle-kit
This commit is contained in:
parent
d72150f578
commit
e65328d025
8 changed files with 1186 additions and 25 deletions
10
db-datos/drizzle.config.ts
Normal file
10
db-datos/drizzle.config.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import type { Config } from "drizzle-kit";
|
||||
|
||||
export default {
|
||||
schema: "./schema.ts",
|
||||
out: "./drizzle",
|
||||
driver: "better-sqlite",
|
||||
dbCredentials: {
|
||||
url: "../scraper/sqlite.db",
|
||||
},
|
||||
} satisfies Config;
|
8
db-datos/drizzle/0000_blushing_sabretooth.sql
Normal file
8
db-datos/drizzle/0000_blushing_sabretooth.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
CREATE TABLE `precios` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`ean` text NOT NULL,
|
||||
`fetched_at` integer NOT NULL,
|
||||
`precio_centavos` integer,
|
||||
`in_stock` integer,
|
||||
`url` text NOT NULL
|
||||
);
|
65
db-datos/drizzle/meta/0000_snapshot.json
Normal file
65
db-datos/drizzle/meta/0000_snapshot.json
Normal file
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"version": "5",
|
||||
"dialect": "sqlite",
|
||||
"id": "88aa0254-106e-424e-ab66-417ff44bbf0b",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"precios": {
|
||||
"name": "precios",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"ean": {
|
||||
"name": "ean",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"fetched_at": {
|
||||
"name": "fetched_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"precio_centavos": {
|
||||
"name": "precio_centavos",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"in_stock": {
|
||||
"name": "in_stock",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
}
|
||||
}
|
13
db-datos/drizzle/meta/_journal.json
Normal file
13
db-datos/drizzle/meta/_journal.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"version": "5",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "5",
|
||||
"when": 1703373860006,
|
||||
"tag": "0000_blushing_sabretooth",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
11
db-datos/migrate.ts
Normal file
11
db-datos/migrate.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
||||
import Database from "better-sqlite3";
|
||||
import { drizzle } from "drizzle-orm/better-sqlite3";
|
||||
import * as schema from "./schema.js";
|
||||
|
||||
const sqlite = new Database("../scraper/sqlite.db");
|
||||
const db = drizzle(sqlite, { schema });
|
||||
|
||||
await migrate(db, { migrationsFolder: "./drizzle" });
|
||||
|
||||
sqlite.close();
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "db-datos",
|
||||
"type": "module",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
|
@ -10,6 +11,11 @@
|
|||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^9.2.2",
|
||||
"drizzle-kit": "^0.20.7",
|
||||
"drizzle-orm": "^0.29.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/better-sqlite3": "^7.6.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ export const precios = sqliteTable("precios", {
|
|||
precioCentavos: integer("precio_centavos"),
|
||||
inStock: integer("in_stock", { mode: "boolean" }),
|
||||
url: text("url").notNull(),
|
||||
// warcRecordId: text("warc_record_id"),
|
||||
// parserVersion: integer("parser_version"),
|
||||
});
|
||||
|
||||
export type Precio = typeof precios.$inferSelect;
|
||||
|
|
1096
pnpm-lock.yaml
1096
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue