-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --remote
flag for remote connection
#10352
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a7012e9
feat: check for --remote
bholmesdev 00c873f
chore: remove bad ticketing example cols
bholmesdev be2fe3d
fix: get seed file working with build
bholmesdev 02e1bec
Revert "fix: get seed file working with build"
bholmesdev 28a0b04
fix: seed from build instead of runtime
bholmesdev ea5b68d
refactor: move recreateTables out of runtime
bholmesdev e9f746b
Revert "refactor: move recreateTables out of runtime"
bholmesdev 6458421
fix: in-memory db for test fixture
bholmesdev c9ef8f2
chore: changeset
bholmesdev c620db5
refactor: generate random db name instead
bholmesdev 50fea2b
refactor: use yargs-parser for flag
bholmesdev 8af1f04
chore: remove in-memory db logi
bholmesdev 1ffa889
refactor: rename random id flag for clarity
bholmesdev ba10739
feat: support --remote in dev
bholmesdev 9d61c71
feat: support --remote on shell
bholmesdev 7315f30
refactor: inline db client
bholmesdev 4696b9d
feat: support --remote on db execute
bholmesdev c2e7a7b
chore: stray console log
bholmesdev aee4425
chore: remove recreateTables from runtime
bholmesdev e527c93
chore: update seeding for new signature
bholmesdev ff057e1
chore: remove unused error imports
bholmesdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@astrojs/db": minor | ||
--- | ||
|
||
Introduce `astro build --remote` to build with a remote database connection. Running `astro build` plain will use a local database file, and `--remote` will authenticate with a studio app token. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,38 @@ | ||
import type { AstroConfig } from 'astro'; | ||
import { sql } from 'drizzle-orm'; | ||
import type { Arguments } from 'yargs-parser'; | ||
import { createRemoteDatabaseClient } from '../../../../runtime/db-client.js'; | ||
import { | ||
createRemoteDatabaseClient, | ||
createLocalDatabaseClient, | ||
} from '../../../../runtime/db-client.js'; | ||
import { getManagedAppTokenOrExit } from '../../../tokens.js'; | ||
import type { DBConfigInput } from '../../../types.js'; | ||
import { getRemoteDatabaseUrl } from '../../../utils.js'; | ||
import { DB_PATH } from '../../../consts.js'; | ||
import { SHELL_QUERY_MISSING_ERROR } from '../../../errors.js'; | ||
|
||
export async function cmd({ | ||
flags, | ||
astroConfig, | ||
}: { | ||
dbConfig: DBConfigInput; | ||
astroConfig: AstroConfig; | ||
flags: Arguments; | ||
}) { | ||
const query = flags.query; | ||
const appToken = await getManagedAppTokenOrExit(flags.token); | ||
const db = createRemoteDatabaseClient(appToken.token, getRemoteDatabaseUrl()); | ||
// Temporary: create the migration table just in case it doesn't exist | ||
const result = await db.run(sql.raw(query)); | ||
await appToken.destroy(); | ||
console.log(result); | ||
if (!query) { | ||
console.error(SHELL_QUERY_MISSING_ERROR); | ||
process.exit(1); | ||
} | ||
if (flags.remote) { | ||
const appToken = await getManagedAppTokenOrExit(flags.token); | ||
const db = createRemoteDatabaseClient(appToken.token, getRemoteDatabaseUrl()); | ||
const result = await db.run(sql.raw(query)); | ||
await appToken.destroy(); | ||
console.log(result); | ||
} else { | ||
const db = createLocalDatabaseClient({ dbUrl: new URL(DB_PATH, astroConfig.root).href }); | ||
const result = await db.run(sql.raw(query)); | ||
console.log(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this regenerated when some HMR change is triggered or when we restart the server? Is it fine if it is regenerated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be regenerated for our test runners! See comment on the basics test. In short, the test runner starts multiple dev servers in parallel if it finds this optimal (does not occur locally for some reason). If there's multiple servers pointing to the same db file, seed data will be clobbered. We also can't inject a db name as an environment variable because then the environment variable would get clobbered by each test run 😅 This is the best compromise I could find
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, if you're wondering if the ID is stable for the lifetime of the test, it seems to be. Can't think of an HMR trigger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you for the detailed explanation :) just making sure if that's what we need