Add white migration (#3334)

This PR adds a down migration for #3321.

### Change Type

- [x] `sdk` — Changes the tldraw SDK
- [x] `dunno` — I don't know
This commit is contained in:
Steve Ruiz 2024-04-04 19:16:17 +01:00 committed by GitHub
parent 0161ec796e
commit 43edeb09b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 3 deletions

View file

@ -2387,7 +2387,7 @@
}, },
{ {
"kind": "Content", "kind": "Content",
"text": "Value | (() => Value)" "text": "(() => Value) | Value"
}, },
{ {
"kind": "Content", "kind": "Content",
@ -2813,7 +2813,7 @@
}, },
{ {
"kind": "Content", "kind": "Content",
"text": "undefined | any[]" "text": "any[] | undefined"
}, },
{ {
"kind": "Content", "kind": "Content",

View file

@ -2030,6 +2030,34 @@ describe('Fractional indexing for line points', () => {
}) })
}) })
describe('add white', () => {
const { up, down } = rootShapeMigrations.migrators[rootShapeVersions.AddWhite]
test('up works as expected', () => {
expect(
up({
props: {},
})
).toEqual({
props: {},
})
})
test('down works as expected', () => {
expect(
down({
props: {
color: 'white',
},
})
).toEqual({
props: {
color: 'black',
},
})
})
})
/* --- PUT YOUR MIGRATIONS TESTS ABOVE HERE --- */ /* --- PUT YOUR MIGRATIONS TESTS ABOVE HERE --- */
for (const migrator of allMigrators) { for (const migrator of allMigrators) {

View file

@ -87,11 +87,12 @@ export const rootShapeVersions = {
AddIsLocked: 1, AddIsLocked: 1,
HoistOpacity: 2, HoistOpacity: 2,
AddMeta: 3, AddMeta: 3,
AddWhite: 4,
} as const } as const
/** @internal */ /** @internal */
export const rootShapeMigrations = defineMigrations({ export const rootShapeMigrations = defineMigrations({
currentVersion: rootShapeVersions.AddMeta, currentVersion: rootShapeVersions.AddWhite,
migrators: { migrators: {
[rootShapeVersions.AddIsLocked]: { [rootShapeVersions.AddIsLocked]: {
up: (record) => { up: (record) => {
@ -147,6 +148,22 @@ export const rootShapeMigrations = defineMigrations({
} }
}, },
}, },
[rootShapeVersions.AddWhite]: {
up: (record) => {
return {
...record,
}
},
down: (record) => {
return {
...record,
props: {
...record.props,
color: record.props.color === 'white' ? 'black' : record.props.color,
},
}
},
},
}, },
}) })