Skip to content

OCC commands

René Gieling edited this page Aug 14, 2025 · 6 revisions

Available occ Commands

Note: In any case make sure you have a backup of your database and only use these commands if your are know what you are doing. Although no data loss is reported until now caused from the usage of these commands (especially these from the polls:db namespace).

All command require polls to be enabled and are not available after uninstall or while in maintenance mode.

Overview

Command Description
polls:index:remove:foreign-key-constraints Remove foreign key constraints
polls:index:remove:unique-indices Remove unique indices
polls:index:remove:optional Remove optional indices
polls:index:create Create essential indices
polls:db:clean-migrations Remove migration entries
polls:db:reset-watch Refresh watch table
polls:db:rebuild Rebuild tables
polls:db:purge Purge Polls
polls:poll:transfer-ownership <source-user> <target-user> Transfer ownership
polls:share:add [--user USER] [--group GROUP] [--email EMAIL] [--] <id> Invite people
polls:share:remove [--user USER] [--group GROUP] [--email EMAIL] [--] <id> Remove share

Indices

Namespace: polls:index

These commands are usually only for analysis or tests. So you should not need them under normal operation mode.

Remove Foreign Key Constraints

Command: occ polls:index:remove:foreign-key-constraints

Note: This is highly NOT RECOMMENDED. These indices are responsible for database health and help avoiding orphaned records. The unique indices grant that by removing a poll all depending records from other tables like options and votes are removed from the database as well. So, if you have to remove them, take care, that the indices are regenerated in time. Otherwise you may have to clean your database manually.

Remove Unique Indices

Command: occ polls:index:remove:unique-indices

Note: This is highly NOT RECOMMENDED. These indices are responsible for database integrity. Besides the unique main key (the entity id) the indices avoid duplication of options, votes and more. Removing this indices may result in a broken application and duplicates ahve to be manually identified and removed, before the indices can get recreated again.

Remove Optional Indices

Command: occ polls:index:remove:optional

Optional indices are for a better database performance. Removing them does no harm to the application, but the database has to do full table scans, especially for complex joins, which actually exist. This can result in heavy performance issues.

Create Essential Indices

Command: occ polls:index:create

This command recreates all foreign key constraints and unique indices

Create Optional Indices

Command: occ db:add-missing-indices

Recreating optional indices is done by the core command and is no more available unter the polls namespace. Refer to the 'Administration settings' of your instance. Missing indices are reported in the 'Security & warnings' section.

Keep in mind, that the creation of optional indices can be time consuming.

Database

Namespace: polls:db

Remove Migration Entries

Command: occ polls:db:clean-migrations

Note: Although this command removes only old polls related migration steps which are not used anymore, you should not use it because it may trigger old migration steps. If really necessary, this will be done while updating polls anyways.

Refresh Watch Table

Command: occ polls:db:reset-watch

The watch table is for temporarily usage and to watch and report in time changes (especially for long polling and periodic polling). This can result in a rapidly rising amount of id numbers. This command just resets the database to start again with id 0. This is done on every update of polls, so you probably should never make usage of it.

Rebuild Tables

Command: occ polls:db:rebuild

Note: This will not build a consistent database when downgrading to a prior major or minor version and new database columns have been added. No database columns get removed if not explicitly listed as orphaned and obsolete column. In this case you have to remove these columns manually.

In any situation, where the database seems to be corrupt, this command checks and corrects issues of the database. In detail it performs the following actions:

  • Remove all foreign key constraints
  • Remove all unique indices
  • Remove all optional indices
  • Remove orphaned tables and columns possibly left over from old installations
  • Checks the table schema and changes all tables to the currently defined database schema
  • Checks hashes of the votes and options table and adds missing ones (based on the unique index definitions) The hashes are short md5 hashes of the poll id and option texts and are essential for fast comparisons and for the unique indices
  • Search for duplicates and orphaned entries and removes them (based on the unique indices including the foreign key constraints) Only one of the duplicates will get left over. Otherwise the index creation would fail.
  • Recreate Foreign key constrains and unique indices

To add the removed optional indices call occ db:add-missing-indices after the recreation was finished without error.

Purge Polls

Command: occ polls:db:purge

Unfortunately or luckily Nextcloud does not remove any tables from the database when uninstalling an app. If you plan to reinstall the app later and want to make sure your already persisted data can be used after the new installation, this is a safe behavior. But if you just want to test polls and decide not to use it further, you have to live with orphaned tables inside your database.

This command allows you to remove all persisted data of polls and wipe it out from your database. So before uninstalling polls you should call occ db:purge. In detail this commands executes the following actions:

  • Purge all foreign key constraint child tables, to make sure parents can be removed also
  • Purge all foreign key constraint parent tables
  • Purge any eventually left over tables of polls
  • Remove all polls related migration records from oc_migrations to make sure a later reinstall is possible
  • Remove all polls related appconfig settings from oc_appconfig

Then remove polls from the apps directory by calling occ app:remove polls

In case you already uninstalled polls, just install it (occ app:install polls) and follow the path above.

Poll Actions

Namespace: polls:poll

Transfer Ownership

Command: occ polls:poll:transfer-ownership <source-user> <target-user>

Transfers the ownership all source user's polls from <source-user> to <target-user>

Shares

Namespace: polls:share

Invite People

Command: polls:share:add [--user USER] [--group GROUP] [--email EMAIL] [--] <id>

Invite people by username, group membership or by email address to poll

Remove Share

Command: polls:share:remove [--user USER] [--group GROUP] [--email EMAIL] [--] <id>

Remove share by username, group or email address from poll

occ polls:index:remove:foreign-key-constraints occ polls:index:remove:unique-indices occ polls:index:remove:optional occ polls:index:create