Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/test-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test & Tag

on:
push:
branches: [ main, LAB_08 ]
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
Expand Down Expand Up @@ -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
git push origin refs/tags/LAB_08
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
118 changes: 118 additions & 0 deletions scripts/SeedDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import mongoose from 'mongoose';
import Product from '../models/Product';

const MONGODB_URI = process.env.MONGODB_URI || 'mongodb+srv://25antonym02:<db_password>@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();