Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: fix migration dialog does not show the correct content in some edge cases (#48239)

Gildas Garciaefc0ad3fcee3
diff --git a/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx b/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
index 24f4763fa21..b893c62e324 100644
--- a/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
+++ b/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
@@ -32,7 +32,7 @@ import { formatMigrationVersionLabel, parseMigrationVersion } from '@/lib/migrat
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
-const Migrations = () => {
+export const Migrations = () => {
const [search, setSearch] = useState('')
const [selectedMigration, setSelectedMigration] = useState<DatabaseMigration>()
const searchInputRef = useRef<HTMLInputElement>(null)
@@ -116,7 +116,7 @@ const Migrations = () => {
placeholder="Search for a migration"
value={search}
className="w-full lg:w-52"
- onChange={(e: any) => setSearch(e.target.value)}
+ onChange={(e) => setSearch(e.target.value)}
icon={<Search />}
/>
<Card>
@@ -221,10 +221,14 @@ const Migrations = () => {
<div className="h-full">
<div className="relative h-full">
<CodeEditor
+ // The CodeEditor does not react to content only changes,
+ // specifically when two projects have migrations with the same version but different content.
+ // Setting the key ensure it always update when the migration changes
+ key={`${project?.ref}-${selectedMigration?.version}`}
isReadOnly
id={selectedMigration?.version ?? ''}
language="pgsql"
- defaultValue={
+ value={
selectedMigration?.statements?.join(';\n') +
(selectedMigration?.statements?.length ? ';' : '')
}
@@ -235,5 +239,3 @@ const Migrations = () => {
</>
)
}
-
-export default Migrations
diff --git a/apps/studio/pages/project/[ref]/database/migrations.tsx b/apps/studio/pages/project/[ref]/database/migrations.tsx
index e57b15dd6fd..425a6ec8762 100644
--- a/apps/studio/pages/project/[ref]/database/migrations.tsx
+++ b/apps/studio/pages/project/[ref]/database/migrations.tsx
@@ -9,7 +9,7 @@ import {
} from 'ui-patterns/PageHeader'
import { PageSection, PageSectionContent } from 'ui-patterns/PageSection'
-import Migrations from '@/components/interfaces/Database/Migrations/Migrations'
+import { Migrations } from '@/components/interfaces/Database/Migrations/Migrations'
import DatabaseLayout from '@/components/layouts/DatabaseLayout/DatabaseLayout'
import { DefaultLayout } from '@/components/layouts/DefaultLayout'
import { DocsButton } from '@/components/ui/DocsButton'