diff --git a/README.md b/README.md index bd4b534..e87e5e9 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ Edit-Screen ### Bare metal am Beispiel Raspberry Pi +- Beschreibung folgt + ### Docker - Baue das image mit `docker build --no-cache -t openlibry .` diff --git a/doc/OpenBiblioImport.md b/doc/OpenBiblioImport.md index c22250c..76a6da3 100644 --- a/doc/OpenBiblioImport.md +++ b/doc/OpenBiblioImport.md @@ -20,76 +20,80 @@ podman machine start - Create a database with name openbiblio in phpmyadmin running on `http://localhost:8080/` - Copy the files over the running container `` -podman cp ./input-21-07-2023/biblio.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_copy.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_copy.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_copy.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_field.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_field.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_field.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_hold.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_hold.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_hold.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_status_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_status_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_status_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_status_hist.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_status_hist.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/biblio_status_hist.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/collection_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/collection_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/collection_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/db.opt mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/material_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/material_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/material_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/mbr_classify_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/mbr_classify_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/mbr_classify_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/member.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/member.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/member.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/member_account.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/member_account.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/member_account.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/session.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/session.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/session.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/settings.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/settings.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/settings.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/staff.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/staff.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/staff.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/state_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/state_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/state_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/theme.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/theme.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/theme.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/transaction_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/transaction_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/transaction_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_block_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_block_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_block_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_indicator_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_indicator_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_indicator_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_subfield_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_subfield_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_subfield_dm.frm mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_tag_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_tag_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio -podman cp ./input-21-07-2023/usmarc_tag_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_copy.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_copy.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_copy.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_field.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_field.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_field.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_hold.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_hold.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_hold.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_status_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_status_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_status_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_status_hist.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_status_hist.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/biblio_status_hist.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/collection_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/collection_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/collection_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/db.opt mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/material_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/material_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/material_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/mbr_classify_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/mbr_classify_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/mbr_classify_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/member.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/member.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/member.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/member_account.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/member_account.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/member_account.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/session.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/session.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/session.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/settings.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/settings.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/settings.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/staff.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/staff.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/staff.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/state_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/state_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/state_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/theme.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/theme.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/theme.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/transaction_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/transaction_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/transaction_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_block_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_block_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_block_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_indicator_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_indicator_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_indicator_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_subfield_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_subfield_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_subfield_dm.frm mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_tag_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_tag_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio +podman cp ./input-22-09-2023/usmarc_tag_dm.frm mysql-server-db:/var/lib/mysql/openbiblio `` -- Export the following tables as json, sort them by date `create_dt`: `member`, `biblio_status_hist`, `biblio`, `biblio_field`, `biblio_copy`. Copy them together in `book_all.json`. It is important to sort by date, because the history of rentals needs to be in the correct order. *IMPORTANT* don't click on export, first do the sorted SQL query and then export the query result as json. +- Export the following tables as json, sort them by date `create_dt`: `member`, `biblio_status_hist`, `biblio`, `biblio_field`, `biblio_copy`. Copy them together in `book_all.json` (this is a bit tedious). It is important to sort by date (oldest first), because the history of rentals needs to be in the correct order. +*IMPORTANT* don't click on export, first do the sorted SQL query and then export the query result as json. For example, the member export has the query `SELECT * FROM member ORDER BY member.create_dt ASC` +![book_all.json Structure](./openbiblio_import_structure.png) - In openlibry delete the database file `dev.db` and the `migrations` folder if it exists. Then recreate them with `npx prisma migrate dev --name init` +- Run the app using `npm run dev` + - Use API to import members `curl -X POST -H "Content-Type: application/json" -d @member.json http://localhost:3000/api/openbiblioimport/migrateUsers` diff --git a/doc/openbiblio_import_structure.png b/doc/openbiblio_import_structure.png new file mode 100644 index 0000000..1175f8a Binary files /dev/null and b/doc/openbiblio_import_structure.png differ diff --git a/entities/book.ts b/entities/book.ts index f3e0714..54297bc 100644 --- a/entities/book.ts +++ b/entities/book.ts @@ -297,7 +297,7 @@ export async function rentBook( client: PrismaClient, userid: number, bookid: number, - duration: number = 14 + duration: number = 21 ) { //change due date, connect to user //put all into one transaction diff --git a/pages/api/openbiblioimport/migrateBooks.ts b/pages/api/openbiblioimport/migrateBooks.ts index 56355e6..82ec877 100644 --- a/pages/api/openbiblioimport/migrateBooks.ts +++ b/pages/api/openbiblioimport/migrateBooks.ts @@ -1,14 +1,11 @@ import { PrismaClient } from "@prisma/client"; -import { BookType } from "../../../entities/BookType"; import type { NextApiRequest, NextApiResponse } from "next"; -import { addBook, deleteAllBooks } from "@/entities/book"; -import { getUser } from "@/entities/user"; +import { BookType } from "../../../entities/BookType"; import dayjs from "dayjs"; -import timezone from "dayjs/plugin/timezone"; import customParseFormat from "dayjs/plugin/customParseFormat"; +import timezone from "dayjs/plugin/timezone"; import utc from "dayjs/plugin/utc"; -import { UserType } from "@/entities/UserType"; export const TIMEZONE = "Europe/Berlin"; dayjs.extend(utc); @@ -237,7 +234,7 @@ export default async function handler( const booklist = req.body as any; //console.log("Booklist", booklist); const bookCopy = booklist.biblio_copy[2].data; - //for some reason, the real ID of the book is in the hist table.. didn't get it + //for some reason, the real ID of the book is in the copy table.. didn't get it const bookIDMapping = createBookIDMapping(bookCopy); //filter out the books that have no barcode.. //console.log("Book ID Mapping", bookIDMapping); @@ -294,7 +291,7 @@ export default async function handler( (u.topic5 ??= " "), imageLink: "", } as BookType; - //console.log("Adding book", book); + console.log("Adding book", book); //transaction.push(addBook(prisma, book)); //addBook(prisma, book); transaction.push(prisma.book.create({ data: { ...book } })); @@ -320,11 +317,11 @@ export default async function handler( ? dayjs(u.due_back_dt, "YYYY-MM-DD", true).toDate() : undefined; - //console.log("Timestamps: ", rentedTime, dueDate); + console.log("Timestamps: ", rentedTime, dueDate); //connect the book to the user, if it still exists - //console.log("Connecting user ", u.mbrid); + console.log("Connecting user ", u.mbrid); if (existingUsers.has(parseInt(u.mbrid))) { rentalStatusCount++; transaction.push( @@ -363,7 +360,7 @@ export default async function handler( //Attach additional fields from the fields table in OpenBiblio let additionalFieldsCount = 0; - //console.log(bookExtraFields); + console.log(bookExtraFields); bookExtraFields.map((f: any) => { const barcodeID = bookIDMapping[f.bibid]; if (isNaN(barcodeID)) { diff --git a/pages/rental/index.tsx b/pages/rental/index.tsx index ec10013..299d7e2 100644 --- a/pages/rental/index.tsx +++ b/pages/rental/index.tsx @@ -99,7 +99,7 @@ export default function Rental({ books, users, rentals }: RentalPropsType) { console.log("Extending book ", bookid, book); const newbook = replaceBookStringDate(book) as any; //extend logic - const newDueDate = extendWeeks(book.dueDate as Date, 2); + const newDueDate = extendWeeks(book.dueDate as Date, 3); newbook.dueDate = newDueDate.toDate(); newbook.renewalCount = newbook.renewalCount + 1; diff --git a/pages/user/[userid].tsx b/pages/user/[userid].tsx index 50f7ffe..33f9308 100644 --- a/pages/user/[userid].tsx +++ b/pages/user/[userid].tsx @@ -121,7 +121,7 @@ export default function UserDetail({ user, books }: any) { const newbook = replaceBookStringDate(book) as any; //extend logic - const newDueDate = extendWeeks(book.dueDate as Date, 2); + const newDueDate = extendWeeks(book.dueDate as Date, 3); newbook.dueDate = newDueDate.toDate(); newbook.renewalCount = newbook.renewalCount + 1; diff --git a/prisma/migrations/20230831132654_init/migration.sql b/prisma/migrations/20230922123042_init/migration.sql similarity index 100% rename from prisma/migrations/20230831132654_init/migration.sql rename to prisma/migrations/20230922123042_init/migration.sql