Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 190 additions & 0 deletions .github/workflows/upgrade-from-older-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# Installs an older Absence, fills it with invented data, moves to the code of
# the pull request and checks that everything entered is still there.
#
# From: 1.0.12 (commit 0d84f4d), which HR used before the betas, and 1.0.0-beta.1.
# How: `occ upgrade` over the replaced folder, or app removed and enabled again.

name: Upgrade from older versions

on: pull_request

permissions:
contents: read

concurrency:
group: upgrade-from-older-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
changes-and-matrix:
runs-on: ubuntu-latest-low
permissions:
contents: read
pull-requests: read

outputs:
src: ${{ steps.changes.outputs.src }}
php-min: ${{ steps.versions.outputs.php-min }}
server-min: ${{ steps.versions.outputs.branches-min }}

steps:
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
id: changes
continue-on-error: true
with:
filters: |
src:
- '.github/workflows/upgrade-from-older-versions.yml'
- 'appinfo/**'
- 'lib/**'
- 'tests/Upgrade/**'

- name: Checkout app
if: steps.changes.outputs.src != 'false'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Get version matrix
if: steps.changes.outputs.src != 'false'
id: versions
uses: nextcloud-libraries/nextcloud-version-matrix@71959de73c244b11ecbf4503b87c41d65b0f64ae # v1.3.4

upgrade:
runs-on: ubuntu-latest

needs: changes-and-matrix
if: needs.changes-and-matrix.outputs.src != 'false'

strategy:
fail-fast: false
matrix:
database: ['sqlite', 'mysql', 'pgsql', 'oci']
from: ['1.0.12', '1.0.0-beta.1']
how: ['upgrade', 'reinstall']
include:
- from: '1.0.12'
ref: 0d84f4da14aea8564ba666d3cfd31f60123302bc
- from: '1.0.0-beta.1'
ref: v1.0.0-beta.1

name: ${{ matrix.from }} ${{ matrix.how }} on ${{ matrix.database }}

services:
mysql:
image: ghcr.io/nextcloud/continuous-integration-mysql-8.4:latest # zizmor: ignore[unpinned-images]
ports:
- 4444:3306/tcp
env:
MYSQL_ROOT_PASSWORD: rootpassword
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
postgres:
image: ghcr.io/nextcloud/continuous-integration-postgres-16:latest # zizmor: ignore[unpinned-images]
ports:
- 4445:5432/tcp
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: rootpassword
POSTGRES_DB: nextcloud
options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5

steps:
- name: Checkout server
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
submodules: true
repository: nextcloud/server
ref: ${{ needs.changes-and-matrix.outputs.server-min }}

- name: Add the viewer app where the server does not ship it
env:
SERVER_BRANCH: ${{ needs.changes-and-matrix.outputs.server-min }}
run: |
# `occ upgrade` refuses to run while an always-enabled app has no files
if [ ! -d apps/viewer ]; then
git clone --depth 1 --branch "$SERVER_BRANCH" https://github.com/nextcloud/viewer.git apps/viewer
fi

- name: Checkout Absence ${{ matrix.from }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ matrix.ref }}
path: apps/absence

- name: Checkout the code to upgrade to
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
path: new-absence

- name: Set up php ${{ needs.changes-and-matrix.outputs.php-min }}
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ needs.changes-and-matrix.outputs.php-min }}
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite, mysql, pdo_mysql, pgsql, pdo_pgsql${{ matrix.database == 'oci' && ', oci8' || '' }}
coverage: none
ini-file: development
ini-values: disable_functions=
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Start Oracle
if: matrix.database == 'oci'
run: |
# Not a service: only these jobs need it, and it is slow to start
docker run -d --name oracle -p 1521:1521 -e ORACLE_PASSWORD=oracle ghcr.io/gvenzl/oracle-free:23 # zizmor: ignore[unpinned-images]
for _ in $(seq 1 60); do
docker exec oracle healthcheck.sh && exit 0
sleep 5
done
docker logs oracle | tail -20
exit 1

- name: Install Nextcloud with Absence ${{ matrix.from }}
env:
DATABASE: ${{ matrix.database }}
run: |
mkdir data
case "$DATABASE" in
sqlite) ./occ maintenance:install --verbose --database=sqlite --admin-user admin --admin-pass admin ;;
mysql) ./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=4444 --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin ;;
pgsql) ./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 --database-port=4445 --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin ;;
oci) ./occ maintenance:install --verbose --database=oci --database-name=FREE --database-host=127.0.0.1 --database-port=1521 --database-user=system --database-pass=oracle --admin-user admin --admin-pass admin ;;
esac
./occ app:enable --force absence
./occ config:app:get absence installed_version

- name: Enter invented data on ${{ matrix.from }}
run: |
php new-absence/tests/Upgrade/upgrade-check.php "$PWD" seed
php new-absence/tests/Upgrade/upgrade-check.php "$PWD" snapshot before.json

- name: Move to the new code
env:
HOW: ${{ matrix.how }}
run: |
installed=$(./occ config:app:get absence installed_version)
new=$(sed -n 's:.*<version>\(.*\)</version>.*:\1:p' new-absence/appinfo/info.xml)
if [ "$installed" = "$new" ]; then
# Unreleased code keeps the version of the last release, and Nextcloud only
# runs migrations for a new version: bump it here like the release will.
sed -i "s:<version>$new</version>:<version>$new.1</version>:" new-absence/appinfo/info.xml
fi
if [ "$HOW" = reinstall ]; then
./occ app:remove absence
mv new-absence apps/absence
./occ app:enable --force absence
else
rm -rf apps/absence
mv new-absence apps/absence
./occ upgrade
fi
./occ config:app:get absence installed_version

- name: Check the data
run: php apps/absence/tests/Upgrade/upgrade-check.php "$PWD" verify before.json
15 changes: 14 additions & 1 deletion SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,14 @@ and to the admin audit log; the region code people set themselves (§7.2) goes t
same history. The weekdays drive the working-days prefill (§7.1); the percentage is
not used for leave yet.

Before HR kept contracts, people set their own working weekdays. The upgrade
(`Version1018…`) turns a valid setting into a period for everyone who has none yet:
`valid_from` is January 1 of the current year (server date), since the setting has
no date and the year's leave is still being counted; the percentage stays empty. The
history entry has no author and `"source": "own_setting"` in its detail. The setting
is then deleted for everybody; an invalid one is dropped. HR corrects the date where
it is wrong.

The annual allowance is **not** derived from the contract: HR sets each person's days
for the year (`absence_entitlements`, §5.5). The same percentage can mean shorter days
on all five weekdays, with the full allowance, or fewer weekdays with fewer days, and
Expand Down Expand Up @@ -2151,9 +2159,14 @@ Recorded during the build so the spec matches the code:
prefill reads the list.
- **Contract data and a profile page** (§6.4, §15.2): HR enters start and end dates and
the working pattern from a date on; the prefill reads those weekdays instead of the
ones people set for themselves, which are dropped (`Version1010…`, app 1.2.0). The
ones people set for themselves, which become a contract period on the upgrade
(`Version1018…`, §6.4) and are then deleted. The
personal section on the Availability page is gone: the region code moved to the
profile page.
- **Shorter table names** (`Version1013…`, `Version1014…`): three tables were renamed
for Oracle's 30-character limit. Each is copied in one transaction, and the old table
is only dropped when the new one holds at least as many rows; otherwise the upgrade
stops with the old table intact.
- **HR → Employees** (§13, §15.2): the *Balances* page became a list of every employee
with their region code, contract, manager and the year's days, flagging missing data,
from one HR-only endpoint (`GET /api/employees`) that costs a fixed number of
Expand Down
16 changes: 2 additions & 14 deletions lib/Migration/Version1010Date20261023100000.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
namespace OCA\Absence\Migration;

use Closure;
use OCA\Absence\AppInfo\Application;
use OCP\Config\IUserConfig;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
Expand All @@ -20,15 +18,10 @@
/**
* Contract data HR keeps per employee (§6.4): start and end date, the working
* weekdays and contract percentage from a date on, and the history of changes.
* The weekdays people set for themselves for the prefill are dropped: HR owns
* them now.
* The weekdays people set for themselves stay until `Version1018…` turns them
* into contract periods, once the tables have their final names.
*/
class Version1010Date20261023100000 extends SimpleMigrationStep {
public function __construct(
private IUserConfig $userConfig,
) {
}

#[\Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
Expand Down Expand Up @@ -71,9 +64,4 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
}
return $changed ? $schema : null;
}

#[\Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$this->userConfig->deleteKey(Application::APP_ID, 'work_weekdays');
}
}
75 changes: 67 additions & 8 deletions lib/Migration/Version1012Date20261111120000.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
use Doctrine\DBAL\Types\Type;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Days are kept as `YYYY-MM-DD` text, like the out-of-office days of the server
* (`dav_absence`). A DATE column comes back with a time part on Oracle, and the
* app reads, compares and sends these values as text everywhere.
*
* Other databases convert the values with the column. Oracle only changes the
* type of a column without values, so there the days are first written as text
* to a new column that then takes the place of the old one.
*/
class Version1012Date20261111120000 extends SimpleMigrationStep {
private const DAYS = [
Expand All @@ -29,6 +34,49 @@ class Version1012Date20261111120000 extends SimpleMigrationStep {
'absence_contract_periods' => ['valid_from'],
];

/** The indexes over a day column: Oracle drops them with the column it replaces */
private const INDEXES = [
'absence_requests' => ['absence_req_range_idx' => [['start_date', 'end_date'], false]],
'absence_holidays' => ['absence_hol_date_idx' => [['date'], false]],
'absence_contract_periods' => ['absence_period_uid_from_uniq' => [['employee_uid', 'valid_from'], true]],
];

public function __construct(
private IDBConnection $db,
) {
}

#[\Override]
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
if ($this->db->getDatabaseProvider() !== IDBConnection::PLATFORM_ORACLE) {
return;
}
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$qb = $this->db->getQueryBuilder();
foreach (self::DAYS as $name => $columns) {
if (!$schema->hasTable($name)) {
continue;
}
$table = $schema->getTable($name);
$quotedTable = $qb->getTableName($name);
foreach ($columns as $columnName) {
if (!$table->hasColumn($columnName) || self::isText($table->getColumn($columnName))) {
continue;
}
$column = $qb->getColumnName($columnName);
$text = $qb->getColumnName($columnName . '_txt');
$this->db->executeStatement("ALTER TABLE $quotedTable ADD ($text VARCHAR2(10))");
$this->db->executeStatement("UPDATE $quotedTable SET $text = TO_CHAR($column, 'YYYY-MM-DD')");
$this->db->executeStatement("ALTER TABLE $quotedTable DROP COLUMN $column");
$this->db->executeStatement("ALTER TABLE $quotedTable RENAME COLUMN $text TO $column");
if ($table->getColumn($columnName)->getNotnull()) {
$this->db->executeStatement("ALTER TABLE $quotedTable MODIFY ($column NOT NULL)");
}
}
}
}

#[\Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
Expand All @@ -45,20 +93,31 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
continue;
}
$column = $table->getColumn($columnName);
// Nextcloud 35 and later hand out their own column, with an enum
// as type; Nextcloud 34 hands out the Doctrine one.
$type = $column->getType();
$wrapped = $type instanceof \BackedEnum;
/** @psalm-suppress UndefinedClass Doctrine is not part of the OCP stubs */
$isText = ($wrapped ? $type->value : Type::lookupName($type)) === Types::STRING;
if (!$isText) {
if (!self::isText($column)) {
/** @psalm-suppress UndefinedClass Doctrine is not part of the OCP stubs */
$column->setType($wrapped ? Types::STRING : Type::getType(Types::STRING));
$column->setType($column->getType() instanceof \BackedEnum ? Types::STRING : Type::getType(Types::STRING));
$column->setLength(10);
$changed = true;
}
}
foreach (self::INDEXES[$name] ?? [] as $index => [$indexed, $unique]) {
if (!$table->hasIndex($index)) {
$unique ? $table->addUniqueIndex($indexed, $index) : $table->addIndex($indexed, $index);
$changed = true;
}
}
}
return $changed ? $schema : null;
}

/**
* Nextcloud 35 and later hand out their own column, with an enum as type;
* Nextcloud 34 hands out the Doctrine one.
*/
private static function isText(object $column): bool {
/** @psalm-suppress MixedMethodCall the column class depends on the server version */
$type = $column->getType();
/** @psalm-suppress UndefinedClass Doctrine is not part of the OCP stubs */
return ($type instanceof \BackedEnum ? $type->value : Type::lookupName($type)) === Types::STRING;
}
}
17 changes: 14 additions & 3 deletions lib/Migration/Version1013Date20261111130000.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* `_seq`, a table name over 23 characters gets a sequence the server cannot
* find again, so nothing could be inserted there.
*
* The rows are copied here, and the next step drops the old tables.
* The rows are copied here, and the next step drops the old tables. Each table
* is copied in one transaction: a copy that fails leaves the new table empty, so
* running the upgrade again copies it from the start.
*/
class Version1013Date20261111130000 extends SimpleMigrationStep {
/** Old name, new name and the columns to copy (every one but the id) */
Expand Down Expand Up @@ -100,9 +102,18 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
foreach (self::RENAMED as [$old, $new, $columns]) {
if ($schema->hasTable($old) && $this->isEmpty($new)) {
$output->info(sprintf('Copied %d rows from %s to %s', $this->copy($old, $new, $columns), $old, $new));
if (!$schema->hasTable($old) || !$this->isEmpty($new)) {
continue;
}
$this->db->beginTransaction();
try {
$copied = $this->copy($old, $new, $columns);
$this->db->commit();
} catch (\Throwable $e) {
$this->db->rollBack();
throw $e;
}
$output->info(sprintf('Copied %d rows from %s to %s', $copied, $old, $new));
}
}

Expand Down
Loading
Loading