Skip to content

Migration Attributes - #46476

Merged
sorbaugh merged 5 commits into
masterfrom
enh/noid/migration-attributes
Jul 30, 2024
Merged

Migration Attributes#46476
sorbaugh merged 5 commits into
masterfrom
enh/noid/migration-attributes

Conversation

@ArtificialOwl

@ArtificialOwlArtificialOwl commented Jul 12, 2024

Copy link
Copy Markdown
Member

tasks

  • generate metadata from core+available apps (apps are temporary enabled during the process if needed)
  • download file from dl.nc.c
  • extract data and compare with already applied Migrations
  • emulate a generic entry in case a new Attribute is implemented in a future version
  • display data using the occ command
  • making endpoint to display result on the webclient (not done yet, but easily doable as code is now out of Command file)
  • commenting and polishing the code

new occ commands

  • running ./occ migrations:generate-metadata to create a JSON file
  • running ./occ migrations:preview <version> to display migration that will be executed if an upgrade to version is initiated

details

When adding some attributes to a migration:

#[DropTable(table: 'old_table')]
#[CreateTable(table: 'new_table', description: 'Table is used to store things, but also to get more things', notes: ['this is a notice', 'and another one, if really needed'])]
#[AddColumn(table: 'my_table')]
#[AddColumn(table: 'my_table', name: 'another_field')]
#[AddColumn(table: 'other_table', name: 'last_one', type: ColumnType::DATE)]
#[AddIndex(table: 'my_table')]
#[AddIndex(table: 'my_table', type: IndexType::PRIMARY)]
#[DropColumn(table: 'other_table')]
#[DropColumn(table: 'other_table', name: 'old_column', description: 'field is not used anymore and replaced by \'last_one\'')]
#[DropIndex(table: 'other_table')]
#[ModifyColumn(table: 'other_table')]
#[ModifyColumn(table: 'other_table', name: 'this_field')]
#[ModifyColumn(table: 'other_table', name: 'this_field', type: ColumnType::BIGINT)]
class Version30000Date20240102030405 extends SimpleMigrationStep {

will display some details when running the preview occ command:

steps to execute implemented new commands:

when using an install made from repository (with apps/testing/ available):

generate metadata from current install:

./occ migrations:generate-metadata > /tmp/nc.metadata

enable testing app:

./occ app:enable testing

delete migration from db:

DELETE FROM oc_migrations WHERE `oc_migrations`.`app` = 'testing' AND `oc_migrations`.`version` = '30000Date20240102030405'

preview future migrations:

./occ migrations:preview /tmp/nc.metadata 

result:
image

Checklist

@ChristophWurstChristophWurst added the pending documentation This pull request needs an associated documentation update label Jul 15, 2024
Comment threadlib/public/Migration/Attributes/MigrationWeight.php Outdated
@ChristophWurst

Copy link
Copy Markdown
Member
  • TableCreation

  • TableDeletion

  • FieldAdd

  • FieldChange

  • FieldRemove

  • IndexAdd

  • IndexRemove

Ease the naming and avoid ambiguity by using standard sql terms

  • CreateTable
  • DeleteTable
  • AddColumn
  • ModifyColumn (consider more specific attributes for type change, rename, etc)
  • DropColumn
  • AddIndex
  • DropIndex

@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/migration-attributes branch from f7638be to c11cae7CompareJuly 17, 2024 11:53
Comment threadcore/Command/Db/Migrations/PreviewCommand.php Fixed
Comment threadcore/Command/Db/Migrations/GenerateMetadataCommand.php Fixed
Comment threadcore/Command/Db/Migrations/PreviewCommand.php Fixed
Comment threadcore/Command/Db/Migrations/PreviewCommand.php Fixed
Comment threadcore/Command/Db/Migrations/PreviewCommand.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/migration-attributes branch from c11cae7 to adb01b2CompareJuly 18, 2024 01:36
Comment threadlib/private/Migration/MetadataManager.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/migration-attributes branch from adb01b2 to 3342cbeCompareJuly 18, 2024 11:29
@ArtificialOwl
ArtificialOwl marked this pull request as ready for review July 18, 2024 11:33
Comment threadlib/public/Migration/Attributes/TableMigrationAttribute.php Outdated
Comment threadlib/public/Migration/Exceptions/AttributeException.php
@ChristophWurst
ChristophWurst requested review from a team, nfebe, sorbaugh and yemkareems and removed request for a teamJuly 18, 2024 11:50
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/migration-attributes branch from 3342cbe to 8682db1CompareJuly 18, 2024 12:06
@AndyScherzingerAndyScherzinger added this to the Nextcloud 30 milestone Jul 18, 2024
@AndyScherzingerAndyScherzinger linked an issue Jul 18, 2024 that may be closed by this pull request
5 tasks
@ChristophWurst

Copy link
Copy Markdown
Member

@AndyScherzinger this does not close #45943. It's the first of five changes

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • All new classes, their methods and properties require @since 30.0.0
  • All new classes require unit test coverage

Comment threadlib/public/Migration/Attributes/DeleteTable.php Outdated
Comment threadlib/public/Migration/Attributes/IndexType.php Outdated
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/migration-attributes branch 3 times, most recently from d54eca5 to 9538865CompareJuly 26, 2024 17:37
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/migration-attributes branch from 9538865 to caffae9CompareJuly 28, 2024 01:25
Comment threadlib/private/Migration/MetadataManager.php Fixed
Comment threadlib/private/Migration/MetadataManager.php Fixed
@ArtificialOwl

Copy link
Copy Markdown
MemberAuthor

psalm error not related: #46846

@ArtificialOwl

Copy link
Copy Markdown
MemberAuthor

when using an install made from repository (with apps/testing/ available):

generate metadata from current install:

./occ migrations:generate-metadata > /tmp/nc.metadata

enable testing app:

./occ app:enable testing

delete migration from db:

DELETE FROM oc_migrations WHERE `oc_migrations`.`app` = 'testing' AND `oc_migrations`.`version` = '30000Date20240102030405'

preview future migrations:

./occ migrations:preview /tmp/nc.metadata 

result:
image

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
d
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
f
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
d
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/migration-attributes branch from 55a5d8e to a9e1dc6CompareJuly 29, 2024 13:45
@ArtificialOwlArtificialOwl added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 29, 2024
@blizzzblizzz mentioned this pull request Jul 30, 2024
@sorbaugh
sorbaugh requested a review from AltahrimJuly 30, 2024 12:53

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attributes look good

@sorbaugh
sorbaugh merged commit 18c0bcb into masterJul 30, 2024
@sorbaugh
sorbaugh deleted the enh/noid/migration-attributes branch July 30, 2024 13:54
@ArtificialOwl

Copy link
Copy Markdown
MemberAuthor

/backport to stable29

@DaphneMuller

Copy link
Copy Markdown
Contributor

@ArtificialOwl please eventually document how to use this command in a portal article, perhaps at the top of https://portal.nextcloud.com/article/Frequently-Asked-Questions/How-to-prepare-for-upgrades#content-database-migrations-between-major-versions

@ChristophWurstChristophWurst removed the pending documentation This pull request needs an associated documentation update label Jun 12, 2025
@ChristophWurst

Copy link
Copy Markdown
Member
image

Developer docs were updated but admin docs are still missing

@ChristophWurstChristophWurst added the pending documentation This pull request needs an associated documentation update label Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewsenhancementfeature: occpending documentationThis pull request needs an associated documentation update🍂 2024-Autumn

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants

@ArtificialOwl@ChristophWurst@DaphneMuller@github-advanced-security@sorbaugh@AndyScherzinger