Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Dec 1, 2023
1 parent 0bf692d commit 802fd4a
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 40 deletions.
2 changes: 1 addition & 1 deletion app/components/forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function ErrorList({
return (
<ul id={id} className="flex flex-col gap-1">
{errorsToRender.map(e => (
<li key={e} className="text-foreground-destructive text-[10px]">
<li key={e} className="text-[10px] text-foreground-destructive">
{e}
</li>
))}
Expand Down
2 changes: 1 addition & 1 deletion app/routes/_auth+/forgot-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default function ForgotPasswordRoute() {
No worries, we'll send you reset instructions.
</p>
</div>
<div className="mx-auto mt-16 min-w-full sm:min-w-[368px] max-w-sm">
<div className="mx-auto mt-16 min-w-full max-w-sm sm:min-w-[368px]">
<forgotPassword.Form method="POST" {...form.props}>
<AuthenticityTokenInput />
<HoneypotInputs />
Expand Down
2 changes: 1 addition & 1 deletion app/routes/_auth+/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function ResetPasswordPage() {
Hi, {data.resetPasswordUsername}. No worries. It happens all the time.
</p>
</div>
<div className="mx-auto mt-16 min-w-full sm:min-w-[368px] max-w-sm">
<div className="mx-auto mt-16 min-w-full max-w-sm sm:min-w-[368px]">
<Form method="POST" {...form.props}>
<Field
labelProps={{
Expand Down
2 changes: 1 addition & 1 deletion app/routes/_auth+/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default function SignupRoute() {
Please enter your email.
</p>
</div>
<div className="mx-auto mt-16 min-w-full sm:min-w-[368px] max-w-sm">
<div className="mx-auto mt-16 min-w-full max-w-sm sm:min-w-[368px]">
<Form method="POST" {...form.props}>
<AuthenticityTokenInput />
<HoneypotInputs />
Expand Down
8 changes: 4 additions & 4 deletions app/routes/settings+/profile.photo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ export default function PhotoRoute() {
pendingIntent === 'submit'
? 'pending'
: lastSubmissionIntent === 'submit'
? actionData?.status ?? 'idle'
: 'idle'
? actionData?.status ?? 'idle'
: 'idle'
}
>
Save Photo
Expand All @@ -230,8 +230,8 @@ export default function PhotoRoute() {
pendingIntent === 'delete'
? 'pending'
: lastSubmissionIntent === 'delete'
? actionData?.status ?? 'idle'
: 'idle'
? actionData?.status ?? 'idle'
: 'idle'
}
>
<Icon name="trash">
Expand Down
8 changes: 4 additions & 4 deletions app/routes/settings+/profile.two-factor.verify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ export default function TwoFactorRoute() {
pendingIntent === 'verify'
? 'pending'
: lastSubmissionIntent === 'verify'
? actionData?.status ?? 'idle'
: 'idle'
? actionData?.status ?? 'idle'
: 'idle'
}
type="submit"
name="intent"
Expand All @@ -212,8 +212,8 @@ export default function TwoFactorRoute() {
pendingIntent === 'cancel'
? 'pending'
: lastSubmissionIntent === 'cancel'
? actionData?.status ?? 'idle'
: 'idle'
? actionData?.status ?? 'idle'
: 'idle'
}
type="submit"
name="intent"
Expand Down
2 changes: 1 addition & 1 deletion app/utils/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function resetUserPassword({
username: User['username']
password: string
}) {
const hashedPassword = await getPasswordHash(password);
const hashedPassword = await getPasswordHash(password)
return prisma.user.update({
where: { username },
data: {
Expand Down
12 changes: 6 additions & 6 deletions app/utils/db.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const prisma = remember('prisma', () => {
e.duration < logThreshold * 1.1
? 'green'
: e.duration < logThreshold * 1.2
? 'blue'
: e.duration < logThreshold * 1.3
? 'yellow'
: e.duration < logThreshold * 1.4
? 'redBright'
: 'red'
? 'blue'
: e.duration < logThreshold * 1.3
? 'yellow'
: e.duration < logThreshold * 1.4
? 'redBright'
: 'red'
const dur = chalk[color](`${e.duration}ms`)
console.info(`prisma:query - ${dur} - ${e.query}`)
})
Expand Down
82 changes: 63 additions & 19 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,32 @@ BACKUP OF THE CURRENT DATABASE BEFORE DOING THIS!!**
```

## Troubleshooting

### Faulty Prisma Migration
If you accidentally run a faulty migration on prod DB, and you see this message in the logs:

If you accidentally run a faulty migration on prod DB, and you see this message
in the logs:

```sh
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
```

You've got a few options:
1. If you don't care about the data, you can delete the app on fly and re-deploy it after deleting/fixing the faulty migration.
2. If you have a recent backup of the DB, you can restore it and re-deploy the app after deleting/fixing the faulty migration. **(Make sure that the backup isn't too old, otherwise you'll lose data)**
- You can fix a faulty migration by either editing the migration SQL file, or by deleting the particular migration folder from `prisma/migrations` and re-generating the migration after fixing the error.
3. If you do care about the data and don't have a backup, you can follow these steps:
1. Comment out the [`exec` section from `litefs.yml` file](https://github.com/epicweb-dev/epic-stack/blob/main/other/litefs.yml#L31-L37).

1. If you don't care about the data, you can delete the app on fly and re-deploy
it after deleting/fixing the faulty migration.
2. If you have a recent backup of the DB, you can restore it and re-deploy the
app after deleting/fixing the faulty migration. **(Make sure that the backup
isn't too old, otherwise you'll lose data)**
- You can fix a faulty migration by either editing the migration SQL file, or
by deleting the particular migration folder from `prisma/migrations` and
re-generating the migration after fixing the error.
3. If you do care about the data and don't have a backup, you can follow these
steps:

1. Comment out the
[`exec` section from `litefs.yml` file](https://github.com/epicweb-dev/epic-stack/blob/main/other/litefs.yml#L31-L37).

```yml
# exec:
# - cmd: node ./other/setup-swap.js
Expand All @@ -295,17 +310,37 @@ You've got a few options:

# - cmd: npm start
```

2. Commit this change and deploy the app to fly.
- This will make sure that after building the dockerfile and deploying it to the fly machine, the `node ./other/setup-swap.js`, `npx prisma migrate deploy` and `npm start` commands won't be executed.
3. Now that the main machine is up and running, you can SSH into it by running `fly ssh console --app [YOUR_APP_NAME]` in the terminal.
4. Create a backup of the DB and download it by following the steps mentioned in the [Manual DB Backups](#manual-db-backups) section.
5. Make a copy of the downloaded DB backup file and store it in a secure location (If something were to go wrong, we have a backup of the backup).
6. Write SQL or use a tool like [DB Browser for SQLite](https://sqlitebrowser.org/) to remove the last (failed) entry from `_prisma_migrations` table from the downloaded DB backup file.
- If you're using DB Browser for SQLite but your DB isn't selectable when selecting a file to open, change DB file extension to `sqlite` from `db`. **Make sure to change it back to `db` before uploading it to the fly machine**.
7. Follow the steps mentioned in the [Manual DB restoration](#manual-db-restoration) section to restore the modified DB backup file to the fly machine.
8. Now the DB is restored, but if you deploy the app with the faulty migration, it will fail again. So you need to delete/fix the faulty migration.
- You can fix a faulty migration by either editing the migration SQL file, or by deleting the particular migration folder from `prisma/migrations` and re-generating the migration after fixing the error.
9. Uncomment the [`exec` section from `litefs.yml` file](https://github.com/epicweb-dev/epic-stack/blob/main/other/litefs.yml#L31-L37).
- This will make sure that after building the dockerfile and deploying it
to the fly machine, the `node ./other/setup-swap.js`,
`npx prisma migrate deploy` and `npm start` commands won't be executed.
3. Now that the main machine is up and running, you can SSH into it by
running `fly ssh console --app [YOUR_APP_NAME]` in the terminal.
4. Create a backup of the DB and download it by following the steps mentioned
in the [Manual DB Backups](#manual-db-backups) section.
5. Make a copy of the downloaded DB backup file and store it in a secure
location (If something were to go wrong, we have a backup of the backup).
6. Write SQL or use a tool like
[DB Browser for SQLite](https://sqlitebrowser.org/) to remove the last
(failed) entry from `_prisma_migrations` table from the downloaded DB
backup file.
- If you're using DB Browser for SQLite but your DB isn't selectable when
selecting a file to open, change DB file extension to `sqlite` from
`db`. **Make sure to change it back to `db` before uploading it to the
fly machine**.
7. Follow the steps mentioned in the
[Manual DB restoration](#manual-db-restoration) section to restore the
modified DB backup file to the fly machine.
8. Now the DB is restored, but if you deploy the app with the faulty
migration, it will fail again. So you need to delete/fix the faulty
migration.
- You can fix a faulty migration by either editing the migration SQL file,
or by deleting the particular migration folder from `prisma/migrations`
and re-generating the migration after fixing the error.
9. Uncomment the
[`exec` section from `litefs.yml` file](https://github.com/epicweb-dev/epic-stack/blob/main/other/litefs.yml#L31-L37).

```yml
exec:
- cmd: node ./other/setup-swap.js
Expand All @@ -315,12 +350,21 @@ You've got a few options:

- cmd: npm start
```
10. Commit this change and deploy the app to fly :tada:
NOTE: Steps 5-7 can be skipped if you can write SQL to remove the faulty migration from the DB. You can use the following SQL query to remove the faulty migration from the DB:
10. Commit this change and deploy the app to fly :tada:
NOTE: Steps 5-7 can be skipped if you can write SQL to remove the faulty
migration from the DB. You can use the following SQL query to remove the
faulty migration from the DB:
```sql
DELETE FROM _prisma_migrations WHERE name = 'migration_name';
```

Make sure to replace `migration_name` with the name of the faulty migration.

This is particularly hard because of how CONSUL leases work. You cannot just simply spin up another machine and access your database from it, because only one machine can get the primary lease. So you have to disable exec commands so the machine that has primary lease can start up, then you can SSH into it and fix the DB.
This is particularly hard because of how CONSUL leases work. You cannot just
simply spin up another machine and access your database from it, because only
one machine can get the primary lease. So you have to disable exec commands so
the machine that has primary lease can start up, then you can SSH into it and
fix the DB.
4 changes: 2 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ const server = app.listen(portToUse, () => {
desiredPort === portToUse
? desiredPort
: addy && typeof addy === 'object'
? addy.port
: 0
? addy.port
: 0

if (portUsed !== desiredPort) {
console.warn(
Expand Down

0 comments on commit 802fd4a

Please sign in to comment.