Workers CI Variables
Ah okay, sry I thought that was just to confirm which build configuration I meant. Question still there. Within the link you provided there‘s an section about build configuration and how to provide build time secrets and variables. I added a secret and try to access it via process.env.DATABASE_URL but it seems like there is no issue available. So I‘m wondering how to get access to this issue from within the drizzle.config.ts file to execute the Migration?
10 Replies
Here's what I'm doing
I have the following repo: https://github.com/helloimalastair/cf-ci-var-test
GitHub
GitHub - helloimalastair/cf-ci-var-test
Contribute to helloimalastair/cf-ci-var-test development by creating an account on GitHub.
I hooked it up to Workers CI with a Build Secret named
MESSAGE
. This is then used in my build script above
And here are the logs from that build:
I forget if creating a thread tags you, so @andifined.dev(sorry if it pings you twice)Don‘t worry thank you very much!
Doesn‘t work for me so
19:03:46.623 Reading config file '/opt/buildhome/repo/drizzle.config.ts' 19:03:46.689 Error Please provide required params for Postgres driver: 19:03:46.689 [x] url: '' 19:03:46.713 Failed: error occurred while running build command import { defineConfig } from 'drizzle-kit'; interface Process { env: { NEON_DATABASE_URL: string; } } declare global { // @ts-ignore const process: Process } export default defineConfig({ out: './drizzle', schema: './drizzle/schema.ts', dialect: 'postgresql', dbCredentials: { url: process.env.NEON_DATABASE_URL!, }, verbose: true });
npx drizzle-kit migrate --config=drizzle.config.ts19:03:46.189
19:03:46.623 Reading config file '/opt/buildhome/repo/drizzle.config.ts' 19:03:46.689 Error Please provide required params for Postgres driver: 19:03:46.689 [x] url: '' 19:03:46.713 Failed: error occurred while running build command import { defineConfig } from 'drizzle-kit'; interface Process { env: { NEON_DATABASE_URL: string; } } declare global { // @ts-ignore const process: Process } export default defineConfig({ out: './drizzle', schema: './drizzle/schema.ts', dialect: 'postgresql', dbCredentials: { url: process.env.NEON_DATABASE_URL!, }, verbose: true });
Here's what I get when adding Drizzle:
So it looks like it works?
Okay that‘s confusing. Will try again with yout adjustments and report the results! In the meantime, thank you very much for your time and examples!!!! Would have some more questions about D1 and calls. Can you help me there as well? Some General questions.
I can try, but I'm afraid I'm not super proficient with either
So D1 related: looking into moving my Database setup to D1 but currently there are too many limitations for be confident in moving. Sice limitations and scaling related one. Do you something about the future roadmap and whats on the horizon there?
Thanks for the honest opinion! So I think I'll do that. It's not the direct access from outside workers, I'm kind of wondering how it should be possible to scale let's say per user base und how to maintain migrations etc. Can't find any architecture examples on that, etc. And if spacing stays at 10GB per database at the moment it's no opion. Thank you very much!
So tested it again with the following changes:
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';
declare global {
namespace NodeJS {
interface ProcessEnv {
NEON_DATABASE_URL: string;
}
}
}
export default defineConfig({
out: './drizzle',
schema: './drizzle/schema.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.NEON_DATABASE_URL!,
},
verbose: true
});
`
"scripts": {
"dev": "wrangler dev",
"test": "vitest",
"cf-typegen": "wrangler types",
"db:generate": "npx drizzle-kit generate --config=drizzle.config.ts",
"db:migrate": "npx drizzle-kit migrate --config=drizzle.config.ts"
}
,
Within worker builds npm run db:migrate get's executed as build command first, than the npx wrangler deploy. But I get the same error as yesterday, that url is not defined.
I make sure to have added the required secrets for the build environment, attached it as screenshot.
Yes that right and I totally understand that choice of design. But my question in relation to architecture is: how to implement that using cf workers and d1 bindings? For example, let's say I would implement a per user choice of design, everytime a new user signs up, automatically a D1 instance for that users should be generated. Don't think it's possible right now to do this using wrangler bindings? Think I have to use the rest api for that? When I would like to query every D1 to get the total count of all rooms created by my community, it's not possible otherwise querying every user instance by itself and I have to keep track of existing users within another D1? And when I have to do some table migrations, I would keep every single D1 instance in sync of course. Maybe I'm just unexperienced here but I don't see a stable and scalable way of doing that. So I'll keep using another serverless db provider where that's not possible, but keeping an eye on changelogs for D1 so maybe one day it's possible to move everything to cloudflare stack, that would be awesome :cloudflare:
Yes maybe, hopefully there will come some changes in the future. Every product should get the opportunity to rise and get better. D1 makes such a promising appearance!
Okay the only difference I've found is, that you've configured a build section within your wangler.jsonc. But when I understand the documentation correct the automated worker build doesn't respect this at the moment?
Problem found: it's because I encrypt the value as a secret within the dashboard. After adding it again as env variable without encrypting it, it's available at buildtime. But what's the difference?
Okay then I encrypted it afterwards and not it works even with encryption, thank you very much 😄