Skip to content

Commit

Permalink
seed from prisma environment url
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Dec 24, 2024
1 parent 6d34c93 commit a8a130b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions gdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ export class GDF {
if (url.startsWith('file:')) return URL.parse(url).pathname
}

get prismaEnv() {
const schema = path.join(this._appdir, 'prisma/schema.prisma')
if (!fs.existsSync(schema)) return null

const schemaContent = fs.readFileSync(schema, 'utf-8')
const urlMatch = schemaContent.match(/url\s*=\s*env\("(.*?)"\)/)
if (urlMatch) return urlMatch[1]
}

get prismaSeed() {
return this.prisma && this.#pj.prisma?.seed
}
Expand Down
6 changes: 5 additions & 1 deletion templates/docker-entrypoint.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ if (process.env.DATABASE_URL) {
<%= tab(2) %>source = path.resolve('./.output/server', '<%- prismaFile %>')
<%= tab(2) %>if (!fs.existsSync(source) && fs.existsSync('/data')) fs.symlinkSync(target, source)
<% } -%>
<% } else if (prismaSeed && sqlite3) { -%>
<%= tab(2) %>const url = new URL(process.env.<%= prismaEnv %>)
<%= tab(2) %>const target = url.protocol === 'file:' && url.pathname
<%= tab(2) %>const newDb = target && !fs.existsSync(target)
<% } -%>
<% if (prismaFile && prismaSeed && sqlite3) { -%>
<%= tab(2) %>const newDb = !fs.existsSync(target)
<% } -%>
<%= tab(2) %>await exec('<%= npx %> prisma migrate deploy')
<% if (prismaFile && prismaSeed && sqlite3) { -%>
<% if (prismaSeed && sqlite3 && (prismaFile || prismaEnv)) { -%>
<%= tab(2) %>if (newDb) await exec('npx prisma db seed')
<% } -%>
<% } -%>
Expand Down
4 changes: 4 additions & 0 deletions test/base/windows/docker-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const env = { ...process.env }
;(async() => {
// If running the web server then migrate existing database
if (process.argv.slice(2).join(' ') === 'npx remix-serve ./build/index.js') {
const url = new URL(process.env.DATABASE_URL)
const target = url.protocol === 'file:' && url.pathname
const newDb = target && !fs.existsSync(target)

Check failure on line 12 in test/base/windows/docker-entrypoint.js

View workflow job for this annotation

GitHub Actions / test

'fs' is not defined

Check failure on line 12 in test/base/windows/docker-entrypoint.js

View workflow job for this annotation

GitHub Actions / test

'fs' is not defined
await exec('npx prisma migrate deploy')
if (newDb) await exec('npx prisma db seed')
}

// launch application
Expand Down
3 changes: 3 additions & 0 deletions test/frameworks/remix-epic/docker-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const env = { ...process.env }
;(async() => {
// If running the web server then migrate existing database
if (process.argv.slice(2).join(' ') === 'npm run start' && process.env.FLY_REGION === process.env.PRIMARY_REGION) {
const url = new URL(process.env.)
const target = url.protocol === 'file:' && url.pathname
const newDb = target && !fs.existsSync(target)
await exec('npx prisma migrate deploy')
}

Expand Down
4 changes: 4 additions & 0 deletions test/frameworks/remix-indie/docker-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const env = { ...process.env }
;(async() => {
// If running the web server then migrate existing database
if (process.argv.slice(2).join(' ') === 'npx remix-serve ./build/index.js') {
const url = new URL(process.env.DATABASE_URL)
const target = url.protocol === 'file:' && url.pathname
const newDb = target && !fs.existsSync(target)

Check failure on line 12 in test/frameworks/remix-indie/docker-entrypoint.js

View workflow job for this annotation

GitHub Actions / test

'fs' is not defined

Check failure on line 12 in test/frameworks/remix-indie/docker-entrypoint.js

View workflow job for this annotation

GitHub Actions / test

'fs' is not defined
await exec('npx prisma migrate deploy')
if (newDb) await exec('npx prisma db seed')
}

// launch application
Expand Down

0 comments on commit a8a130b

Please sign in to comment.