-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_database.php
More file actions
59 lines (52 loc) · 2.04 KB
/
setup_database.php
File metadata and controls
59 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* NocoDB Database Setup Script for MUNdig (v5 - Ingredients per Step)
*/
$nocoUrl = "http://localhost:8080";
$nocoToken = "krmdjfNKDfPW9D5iwifxM77eGOTO6sEMtjsY6eDF";
function nocoRequest($method, $endpoint, $data = null) {
global $nocoUrl, $nocoToken;
$url = $nocoUrl . $endpoint;
$ch = curl_init($url);
$headers = ["xc-token: $nocoToken", "Content-Type: application/json"];
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if ($data) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ['code' => $httpCode, 'data' => json_decode($response, true), 'raw' => $response];
}
echo "Starting NocoDB Setup v5...\n";
// Find Base
$resp = nocoRequest("GET", "/api/v1/db/meta/projects");
$baseId = null;
$list = $resp['data']['list'] ?? $resp['data'] ?? [];
foreach ($list as $base) {
if (isset($base['title']) && $base['title'] === "MUNdig") {
$baseId = $base['id'];
break;
}
}
if (!$baseId) die("Error: Base MUNdig not found.\n");
// Update Table RecipeSteps to include ingredients info
$tables = [
[
"table_name" => "RecipeSteps",
"title" => "Rezept-Schritte",
"columns" => [
["column_name" => "RecipeID", "title" => "Rezept ID", "uidt" => "SingleLineText"],
["column_name" => "SortOrder", "title" => "Reihenfolge", "uidt" => "Number"],
["column_name" => "Instruction", "title" => "Anweisung", "uidt" => "LongText", "pv" => true],
["column_name" => "IngredientsInfo", "title" => "Zugehörige Zutaten", "uidt" => "LongText"] // For storing step-specific ingredients
]
]
];
foreach ($tables as $t) {
echo "Updating table: " . $t['title'] . "\n";
$res = nocoRequest("POST", "/api/v1/db/meta/projects/$baseId/tables", $t);
echo "Status: " . $res['code'] . "\n";
}
echo "Database Update Complete.\n";
?>