MCPcopy Create free account
hub / github.com/epicweb-dev/full-stack-foundations / updateDataDb

Function updateDataDb

epicshop/fix.js:104–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102}
103
104async function updateDataDb() {
105 let latestPrismaApp
106
107 const appsWithPrisma = apps.filter(app => exists(path.join(app, 'prisma')))
108 // copy this to all the other apps
109 for (const app of appsWithPrisma) {
110 const prismaIsUnchanged = latestPrismaApp
111 ? await dirsAreTheSame(
112 path.join(latestPrismaApp, 'prisma'),
113 path.join(app, 'prisma'),
114 [/data\.db/],
115 )
116 : false
117 if (!prismaIsUnchanged) {
118 if (latestPrismaApp) {
119 logVerbose(
120 `The prisma folder in ${rel(app)} is different to ${rel(
121 latestPrismaApp,
122 )}. Updating the latest.`,
123 )
124 } else {
125 logVerbose(`Setting the latest prisma app to ${rel(app)}`)
126 }
127 latestPrismaApp = app
128 await reseedIfNecessary(latestPrismaApp)
129 }
130 const pathToLatestAppDb = path.join(latestPrismaApp, 'prisma/data.db')
131 const pathToDestAppDb = path.join(app, 'prisma/data.db')
132 if (pathToLatestAppDb !== pathToDestAppDb) {
133 if (!isSameFile(pathToLatestAppDb, pathToDestAppDb)) {
134 console.log(
135 `Copying data.db from ${rel(latestPrismaApp)} to ${rel(app)}`,
136 )
137 await fs.promises.copyFile(pathToLatestAppDb, pathToDestAppDb)
138 } else {
139 logVerbose(
140 `Skipping copying ${rel(pathToLatestAppDb)} to ${rel(
141 pathToDestAppDb,
142 )} because they are the same`,
143 )
144 }
145 }
146 }
147}
148
149function isSameFile(file1, file2) {
150 const f1IsFile = isFile(file1)

Callers 1

fix.jsFile · 0.85

Calls 6

existsFunction · 0.85
dirsAreTheSameFunction · 0.85
logVerboseFunction · 0.85
relFunction · 0.85
reseedIfNecessaryFunction · 0.85
isSameFileFunction · 0.85

Tested by

no test coverage detected