Cleanup: Remove legacy Payload-dependent scripts
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🩺 Smoke Test (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🩺 Smoke Test (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
This commit is contained in:
@@ -1,54 +0,0 @@
|
|||||||
import { getPayload } from "payload";
|
|
||||||
import configPromise from "./payload.config";
|
|
||||||
import fs from "fs";
|
|
||||||
import path from "path";
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
try {
|
|
||||||
const payload = await getPayload({ config: configPromise });
|
|
||||||
console.log("Payload initialized.");
|
|
||||||
|
|
||||||
const docsDir = path.resolve(process.cwd(), "docs");
|
|
||||||
|
|
||||||
if (!fs.existsSync(docsDir)) {
|
|
||||||
console.log(`Docs directory not found at ${docsDir}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = fs.readdirSync(docsDir);
|
|
||||||
let count = 0;
|
|
||||||
|
|
||||||
for (const file of files) {
|
|
||||||
if (file.endsWith(".md")) {
|
|
||||||
const content = fs.readFileSync(path.join(docsDir, file), "utf8");
|
|
||||||
|
|
||||||
// Check if already exists
|
|
||||||
const existing = await payload.find({
|
|
||||||
collection: "context-files",
|
|
||||||
where: { filename: { equals: file } },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing.totalDocs === 0) {
|
|
||||||
await payload.create({
|
|
||||||
collection: "context-files",
|
|
||||||
data: {
|
|
||||||
filename: file,
|
|
||||||
content: content,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Migration successful! Added ${count} new context files to the database.`,
|
|
||||||
);
|
|
||||||
process.exit(0);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Migration failed:", e);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import { getPayload } from "payload";
|
|
||||||
import configPromise from "./payload.config";
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
const payload = await getPayload({ config: configPromise });
|
|
||||||
const { docs } = await payload.find({
|
|
||||||
collection: "posts",
|
|
||||||
limit: 1000,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`Found ${docs.length} posts. Checking status...`);
|
|
||||||
|
|
||||||
for (const doc of docs) {
|
|
||||||
if (doc._status !== "published") {
|
|
||||||
try {
|
|
||||||
await payload.update({
|
|
||||||
collection: "posts",
|
|
||||||
id: doc.id,
|
|
||||||
data: {
|
|
||||||
_status: "published",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log(`Updated "${doc.title}" to published.`);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Failed to update ${doc.title}:`, e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Migration complete.");
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
import { getPayload } from "payload";
|
|
||||||
import configPromise from "./payload.config";
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
const payload = await getPayload({ config: configPromise });
|
|
||||||
const { docs } = await payload.find({
|
|
||||||
collection: "posts",
|
|
||||||
limit: 1000,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Found ${docs.length} posts. Checking for <TableOfContents />...`,
|
|
||||||
);
|
|
||||||
|
|
||||||
let updatedCount = 0;
|
|
||||||
|
|
||||||
const removeTOC = (node: any): boolean => {
|
|
||||||
let modified = false;
|
|
||||||
if (node.children && Array.isArray(node.children)) {
|
|
||||||
// Filter out raw text nodes or paragraph nodes that are exactly TableOfContents
|
|
||||||
const originalLength = node.children.length;
|
|
||||||
node.children = node.children.filter((child: any) => {
|
|
||||||
if (
|
|
||||||
child.type === "text" &&
|
|
||||||
child.text &&
|
|
||||||
child.text.includes("<TableOfContents />")
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
child.type === "paragraph" &&
|
|
||||||
child.children &&
|
|
||||||
child.children.length === 1 &&
|
|
||||||
child.children[0].text === "<TableOfContents />"
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
if (node.children.length !== originalLength) {
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also clean up any substrings in remaining text nodes
|
|
||||||
for (const child of node.children) {
|
|
||||||
if (
|
|
||||||
child.type === "text" &&
|
|
||||||
child.text &&
|
|
||||||
child.text.includes("<TableOfContents />")
|
|
||||||
) {
|
|
||||||
child.text = child.text.replace("<TableOfContents />", "").trim();
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
if (removeTOC(child)) {
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return modified;
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const doc of docs) {
|
|
||||||
if (doc.content?.root) {
|
|
||||||
const isModified = removeTOC(doc.content.root);
|
|
||||||
if (isModified) {
|
|
||||||
try {
|
|
||||||
await payload.update({
|
|
||||||
collection: "posts",
|
|
||||||
id: doc.id,
|
|
||||||
data: {
|
|
||||||
content: doc.content,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log(`Cleaned up TOC in "${doc.title}".`);
|
|
||||||
updatedCount++;
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Failed to update ${doc.title}:`, e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Cleanup complete. Modified ${updatedCount} posts.`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import { getPayload } from "payload";
|
|
||||||
import configPromise from "../payload.config";
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
try {
|
|
||||||
const payload = await getPayload({ config: configPromise });
|
|
||||||
|
|
||||||
const existing = await payload.find({
|
|
||||||
collection: "users",
|
|
||||||
where: { email: { equals: "marc@mintel.me" } },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing.totalDocs > 0) {
|
|
||||||
console.log("User already exists, updating password...");
|
|
||||||
await payload.update({
|
|
||||||
collection: "users",
|
|
||||||
where: { email: { equals: "marc@mintel.me" } },
|
|
||||||
data: {
|
|
||||||
password: "Tim300493.",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log("Password updated.");
|
|
||||||
} else {
|
|
||||||
console.log("Creating user...");
|
|
||||||
await payload.create({
|
|
||||||
collection: "users",
|
|
||||||
data: {
|
|
||||||
email: "marc@mintel.me",
|
|
||||||
password: "Tim300493.",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log("User marc@mintel.me created.");
|
|
||||||
}
|
|
||||||
process.exit(0);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Failed to create user:", err);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
import fs from "node:fs";
|
|
||||||
import * as xlsxImport from "xlsx";
|
|
||||||
const xlsx = (xlsxImport as any).default || xlsxImport;
|
|
||||||
import { getPayload } from "payload";
|
|
||||||
import configPromise from "../payload.config";
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
try {
|
|
||||||
console.log("Initializing Payload...");
|
|
||||||
const payload = await getPayload({ config: configPromise });
|
|
||||||
|
|
||||||
const filePath = "/Users/marcmintel/Downloads/Akquise_Branchen.xlsx";
|
|
||||||
if (!fs.existsSync(filePath)) {
|
|
||||||
console.error("File not found:", filePath);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Reading Excel file: ${filePath}`);
|
|
||||||
const wb = xlsx.readFile(filePath);
|
|
||||||
|
|
||||||
let accountsCreated = 0;
|
|
||||||
let contactsCreated = 0;
|
|
||||||
|
|
||||||
for (const sheetName of wb.SheetNames) {
|
|
||||||
if (
|
|
||||||
sheetName === "Weitere Kundenideen" ||
|
|
||||||
sheetName.includes("BKF Firmen")
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
let industry = sheetName
|
|
||||||
.replace(/^\d+_/, "")
|
|
||||||
.replace(/^\d+\.\s*/, "")
|
|
||||||
.replace(/_/g, " ");
|
|
||||||
console.log(
|
|
||||||
`\n--- Importing Sheet: ${sheetName} -> Industry: ${industry} ---`,
|
|
||||||
);
|
|
||||||
const rows = xlsx.utils.sheet_to_json(wb.Sheets[sheetName]);
|
|
||||||
|
|
||||||
for (const row of rows) {
|
|
||||||
const companyName = row["Unternehmen"]?.trim();
|
|
||||||
const website = row["Webseitenlink"]?.trim();
|
|
||||||
let email = row["Emailadresse"]?.trim();
|
|
||||||
const contactName = row["Ansprechpartner"]?.trim();
|
|
||||||
const position = row["Position"]?.trim();
|
|
||||||
const statusRaw = row["Webseiten-Status (alt/gut/schlecht)"]
|
|
||||||
?.trim()
|
|
||||||
?.toLowerCase();
|
|
||||||
const notes = row["Notizen"]?.trim();
|
|
||||||
|
|
||||||
if (!companyName) continue;
|
|
||||||
|
|
||||||
let websiteStatus = "unknown";
|
|
||||||
if (statusRaw === "gut") websiteStatus = "gut";
|
|
||||||
else if (statusRaw === "ok" || statusRaw === "okay")
|
|
||||||
websiteStatus = "ok";
|
|
||||||
else if (
|
|
||||||
statusRaw === "schlecht" ||
|
|
||||||
statusRaw === "alt" ||
|
|
||||||
statusRaw === "veraltet"
|
|
||||||
)
|
|
||||||
websiteStatus = "schlecht";
|
|
||||||
|
|
||||||
// Find or create account
|
|
||||||
let accountId;
|
|
||||||
const whereClause = website
|
|
||||||
? { website: { equals: website } }
|
|
||||||
: { name: { equals: companyName } };
|
|
||||||
|
|
||||||
const existingAccounts = await payload.find({
|
|
||||||
collection: "crm-accounts",
|
|
||||||
where: whereClause,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingAccounts.docs.length > 0) {
|
|
||||||
accountId = existingAccounts.docs[0].id;
|
|
||||||
console.log(`[SKIP] Account exists: ${companyName}`);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
const newAccount = await payload.create({
|
|
||||||
collection: "crm-accounts",
|
|
||||||
data: {
|
|
||||||
name: companyName,
|
|
||||||
website: website || "",
|
|
||||||
status: "lead",
|
|
||||||
leadTemperature: "cold",
|
|
||||||
industry,
|
|
||||||
websiteStatus,
|
|
||||||
notes,
|
|
||||||
} as any,
|
|
||||||
});
|
|
||||||
accountId = newAccount.id;
|
|
||||||
accountsCreated++;
|
|
||||||
console.log(`[OK] Created account: ${companyName}`);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(
|
|
||||||
`[ERROR] Failed to create account ${companyName}:`,
|
|
||||||
err.message,
|
|
||||||
);
|
|
||||||
continue; // Skip contact creation if account failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle contact
|
|
||||||
if (email) {
|
|
||||||
// Some rows have multiple emails or contacts. Let's just pick the first email if there are commas.
|
|
||||||
if (email.includes(",")) email = email.split(",")[0].trim();
|
|
||||||
|
|
||||||
const existingContacts = await payload.find({
|
|
||||||
collection: "crm-contacts",
|
|
||||||
where: { email: { equals: email } },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingContacts.docs.length === 0) {
|
|
||||||
let firstName = "Team";
|
|
||||||
let lastName = companyName; // fallback
|
|
||||||
|
|
||||||
if (contactName) {
|
|
||||||
// If multiple contacts are listed, just take the first one
|
|
||||||
const firstContact = contactName.split(",")[0].trim();
|
|
||||||
const parts = firstContact.split(" ");
|
|
||||||
if (parts.length > 1) {
|
|
||||||
lastName = parts.pop();
|
|
||||||
firstName = parts.join(" ");
|
|
||||||
} else {
|
|
||||||
firstName = firstContact;
|
|
||||||
lastName = "Contact";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await payload.create({
|
|
||||||
collection: "crm-contacts",
|
|
||||||
data: {
|
|
||||||
email,
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
role: position,
|
|
||||||
account: accountId as any,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
contactsCreated++;
|
|
||||||
console.log(` -> [OK] Created contact: ${email}`);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(
|
|
||||||
` -> [ERROR] Failed to create contact ${email}:`,
|
|
||||||
err.message,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(` -> [SKIP] Contact exists: ${email}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`\nMigration completed successfully!`);
|
|
||||||
console.log(
|
|
||||||
`Created ${accountsCreated} Accounts and ${contactsCreated} Contacts.`,
|
|
||||||
);
|
|
||||||
process.exit(0);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Migration failed:", e);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import { getPayload } from "payload";
|
|
||||||
import configPromise from "./payload.config";
|
|
||||||
import fs from "fs";
|
|
||||||
import path from "path";
|
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
try {
|
|
||||||
let payload;
|
|
||||||
let retries = 5;
|
|
||||||
while (retries > 0) {
|
|
||||||
try {
|
|
||||||
console.log(
|
|
||||||
`Connecting to database (URI: ${process.env.DATABASE_URI || "default"})...`,
|
|
||||||
);
|
|
||||||
payload = await getPayload({ config: configPromise });
|
|
||||||
break;
|
|
||||||
} catch (e: any) {
|
|
||||||
if (
|
|
||||||
e.code === "ECONNREFUSED" ||
|
|
||||||
e.code === "ENOTFOUND" ||
|
|
||||||
e.message?.includes("ECONNREFUSED") ||
|
|
||||||
e.message?.includes("ENOTFOUND") ||
|
|
||||||
e.message?.includes("cannot connect to Postgres")
|
|
||||||
) {
|
|
||||||
console.log(
|
|
||||||
`Database not ready (${e.code || "UNKNOWN"}), retrying in 3 seconds... (${retries} retries left)`,
|
|
||||||
);
|
|
||||||
retries--;
|
|
||||||
await new Promise((res) => setTimeout(res, 3000));
|
|
||||||
} else {
|
|
||||||
console.error("Fatal connection error:", e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!payload) {
|
|
||||||
throw new Error(
|
|
||||||
"Failed to connect to the database after multiple retries.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const existing = await payload.find({
|
|
||||||
collection: "context-files",
|
|
||||||
limit: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing.totalDocs > 0) {
|
|
||||||
console.log("Context collection already populated. Skipping seed.");
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const seedDir = path.resolve(
|
|
||||||
__dirname,
|
|
||||||
"src/payload/collections/ContextFiles/seed",
|
|
||||||
);
|
|
||||||
if (!fs.existsSync(seedDir)) {
|
|
||||||
console.log(`Seed directory not found at ${seedDir}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = fs.readdirSync(seedDir).filter((f) => f.endsWith(".md"));
|
|
||||||
let count = 0;
|
|
||||||
|
|
||||||
for (const file of files) {
|
|
||||||
const content = fs.readFileSync(path.join(seedDir, file), "utf8");
|
|
||||||
await payload.create({
|
|
||||||
collection: "context-files",
|
|
||||||
data: {
|
|
||||||
filename: file,
|
|
||||||
content: content,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Seeded ${count} context files.`);
|
|
||||||
process.exit(0);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Seeding failed:", e);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
Reference in New Issue
Block a user