-
Notifications
You must be signed in to change notification settings - Fork 736
/
Copy pathpostgres.js
141 lines (115 loc) · 3.93 KB
/
postgres.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import utils from "@/utils/index.js";
import yaml from "yaml";
async function dbPostgresGenerate({context,data}) {
/* ;; DB:POSTGRES::GENERATE
make {DRD, db{schemas,seed} } details -> postgres exec commands to {create tables , insert seed examples}
out : ["db"]
*/
const { pm , db } = data
const { drd } = pm
// const {text , attachments} = details
const messages = [
{
"role": "system",
"content": `- you are a genius Postgresql expert
- your role is to write the POSTGRESQL commands that create the DB tables and seed the DB with a good amount of example seed entries, according to the provided details
- your answer should be in this format :
\`\`\`postgresql
[... POSTGRESQL COMMANDS TO CREATE TABLES ...]
[... POSTGRESQL COMMANDS TO SEED THE DB ...]
\`\`\`
ask yourself:
* am i creating all the tables in the required formats ?
* am i seeding the database with enough data ?
give a final, super comprehensive answer in valid, extend POSTGRESQL command to execute
which will be perfectly ready for production and pushed to prod to thousands of users instantly (in a nodejs + POSTGRES ) and work flawlessly
---
important:
> when making seed data , if some field is meant to store an image url, use a https://picsum.photos/ url with a random seed
> important : for seed data, if some entry needs to store an image url, use a https://picsum.photos/ url instead of example.com !!
---
use snake_case for any naming you do
---
very important :
> avoid any postgres-hardcoded methods ie. for generating UIDs etc... ; logic for that stuff will come from nodejs functions !
> do not generate UUIDs or similar inside postgres ! logic for that stuff will come from nodejs functions !
> in case of UUIds or similar, make them normal strings !
your reply should start with : "\`\`\`postgresql" and end with "\`\`\`"
you will be tipped $99999 + major company shares for nailing it perfectly off the bat
you are a genius`
},
{
"role": "user",
"content": `\`\`\`DRD:database-requirements-document
${drd}
\`\`\``
},
{
"role": "user",
"content": `\`\`\`DB:schemas
${yaml.stringify({ schemas: db.schemas })}
\`\`\``
},
/*db.seed && {
"role": "user",
"content": `\`\`\`DB:seed
${yaml.stringify({ schemas: db.seed })}
\`\`\``
},*/
{
"role": "user",
"content": `Generate the POSTGRES command in one single comprehensive answer
it is expected to be very comprehensive and detailed and cover all the provided details
---
very important :
> avoid any postgres-hardcoded methods ie. for generating UIDs etc... or similar ; logic for that stuff will come from nodejs functions !
> do not generate UUIDs or similar inside postgres ! that stuff will come from nodejs functions !
> in case of UUIDs, make them normal strings and not generated inside postgres by postgres methods !
> aim for it to work on any default light postgres without any extra configs or plugins !
> only use basic primitives like numbers, strings, json, etc ... no uuid types or special types etc
> very important : only use basic primitives like numbers, strings, json, etc ... no uuid types or any special types etc ! very basic primitives only !
reply in \`\`\`postgresql\`\`\`
you're a genius`
},
]
const postgres = (
await context.run({
id: "op:LLM::GEN",
context: {
...context, // {streams , project}
operation: {
key: "db.postgres",
meta: {
name: "DB Postgresql",
desc: "db postgres commands {tables,seed}",
},
},
},
data: {
model: process.env.LOCAL_INFERENCE_MODEL,//`gpt-4o`,
messages,
preparser: `backticks`,
parser: false,
}
})
).generated
await context.run({
id: "op:PROJECT::STATE:UPDATE",
context,
data: {
operation: {
id: "db:postgres",
},
type: `end`,
content: {
key: "db.postgres",
data: postgres,
},
}
})
return { db: { ...db, postgres } }
}
export default {
//"DB:POSTGRES::TABLES": dbPostgresTables,
"DB:POSTGRES::GENERATE": dbPostgresGenerate,
}