diff --git a/.github/workflows/test-tag.yml b/.github/workflows/test-tag.yml index d7b0718..a750ebd 100644 --- a/.github/workflows/test-tag.yml +++ b/.github/workflows/test-tag.yml @@ -2,7 +2,7 @@ name: Test & Tag on: push: - branches: [ main, LAB_08 ] + branches: [ main ] pull_request: branches: [ main ] workflow_dispatch: @@ -56,9 +56,22 @@ jobs: if: github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v4 - - name: Tag LAB_08 + with: + fetch-depth: 0 # Fetch all history for tags + + - name: Configure Git run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" + + - name: Delete existing tag if it exists + run: | + # Delete local tag if it exists + git tag -d LAB_08 2>/dev/null || true + # Delete remote tag if it exists + git push origin :refs/tags/LAB_08 2>/dev/null || true + + - name: Create and push new tag + run: | git tag LAB_08 - git push origin LAB_08 \ No newline at end of file + git push origin refs/tags/LAB_08 diff --git a/package-lock.json b/package-lock.json index 009e8bb..332a009 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "check-node-version": "^4.2.1", + "dotenv": "^17.2.1", "fs-extra": "^11.3.0", "mongodb-memory-server": "^10.1.4", "mongoose": "^8.16.1", @@ -4520,6 +4521,18 @@ "node": ">=0.10.0" } }, + "node_modules/dotenv": { + "version": "17.2.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.1.tgz", + "integrity": "sha512-kQhDYKZecqnM0fCnzI5eIv5L4cAe/iRI+HqMbO/hbRdTAeXDG+M9FjipUxNfbARuEg4iHIbhnhs78BCHNbSxEQ==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", diff --git a/package.json b/package.json index b5675f2..ca81dfa 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "build": "next build", "start": "next start", "lint": "next lint", + "seed": "tsx scripts/SeedDatabase.ts", "save": "tsx scripts/SaveProduct.ts", "search": "tsx scripts/SearchProducts.ts", "test": "jest __tests__/unit", @@ -30,6 +31,7 @@ }, "dependencies": { "check-node-version": "^4.2.1", + "dotenv": "^17.2.1", "fs-extra": "^11.3.0", "mongodb-memory-server": "^10.1.4", "mongoose": "^8.16.1", diff --git a/scripts/SeedDatabase.ts b/scripts/SeedDatabase.ts new file mode 100644 index 0000000..fa92643 --- /dev/null +++ b/scripts/SeedDatabase.ts @@ -0,0 +1,118 @@ +import mongoose from 'mongoose'; +import Product from '../models/Product'; + +const MONGODB_URI = process.env.MONGODB_URI || 'mongodb+srv://25antonym02:@wt1-project.0dhupxq.mongodb.net/?retryWrites=true&w=majority&appName=wt1-project'; + +const seedData = [ + { + id: 1, + produkt: "Kaffee", + marke: "Starbucks", + labels: ["Fairtrade", "EU Bio", "Klimaneutral"], + controversy: ["Entwaldung", "Kinderarbeit"], + herkunftsland: "Kolumbien" + }, + { + id: 2, + produkt: "Schokolade (Tafel)", + marke: "Lindt", + labels: ["Fairtrade", "EU Bio"], + controversy: ["Palmölindustrie"], + herkunftsland: "Elfenbeinküste" + }, + { + id: 3, + produkt: "T-Shirt (Baumwolle)", + marke: "H&M", + labels: ["EU Bio", "recycling-Material"], + controversy: ["Textilindustrie"], + herkunftsland: "Bangladesch" + }, + { + id: 4, + produkt: "Smartphone", + marke: "Samsung", + labels: ["Klimaneutral"], + controversy: ["E-Schrott", "Kinderarbeit", "Seltene Erden"], + herkunftsland: "China" + }, + { + id: 5, + produkt: "Mineralwasser (1 l)", + marke: "Gerolsteiner", + labels: ["Klimaneutral", "recycling-Material"], + controversy: ["Wasserprivatisierung"], + herkunftsland: "Deutschland" + }, + { + id: 6, + produkt: "Sneaker", + marke: "Nike", + labels: ["recycling-Material"], + controversy: ["Textilindustrie", "Arbeitsbedingungen"], + herkunftsland: "Vietnam" + }, + { + id: 7, + produkt: "Olivenöl", + marke: "Gaea", + labels: ["EU Bio"], + controversy: ["Monokultur", "Landraub"], + herkunftsland: "Griechenland" + }, + { + id: 8, + produkt: "Laptop-Ladegerät", + marke: "Dell", + labels: ["Klimaneutral"], + controversy: ["E-Schrott"], + herkunftsland: "China" + }, + { + id: 9, + produkt: "Duschgel", + marke: "Yves Rocher", + labels: ["EU Bio", "Klimaneutral"], + controversy: ["Palmölindustrie"], + herkunftsland: "Frankreich" + }, + { + id: 10, + produkt: "Papier (A4, 500 Blatt)", + marke: "Xerox", + labels: ["EU Bio", "recycling-Material"], + controversy: ["Abholzung"], + herkunftsland: "Schweden" + } +]; + +async function seedDatabase() { + try { + // Connect to MongoDB + await mongoose.connect(MONGODB_URI); + console.log('Connected to MongoDB Atlas'); + + // Clear existing data + await Product.deleteMany({}); + console.log('Cleared existing products'); + + // Insert seed data + const insertedProducts = await Product.insertMany(seedData); + console.log(`Inserted ${insertedProducts.length} products`); + + // Create indexes + await Product.collection.createIndex({ "marke": 1 }); + await Product.collection.createIndex({ "labels": 1 }); + await Product.collection.createIndex({ "herkunftsland": 1 }); + console.log('Created indexes'); + + console.log('Seed data inserted successfully!'); + } catch (error) { + console.error('Error seeding database:', error); + } finally { + await mongoose.disconnect(); + console.log('Disconnected from MongoDB'); + } +} + +seedDatabase(); \ No newline at end of file