Source: config/migrations/20260827-tailnet-object-types.js

export const id = '20260827-tailnet-object-types';
export const name = 'Add tailnet to ObjectBase.Type and tailnetRunner to Links.Type enum';

/**
 * Tailnet networks are ObjectsBase objects (Type='tailnet'), one per network a
 * team can create. Multiple networks per group are allowed — the owner group is
 * tracked via Links.Type='memberA' (tailnet -> group), exactly like projects.
 *
 * Links.Type='tailnetRunner': UID = Tailnet-UID, UIDTarget = Runner-UID.
 * A runner can be assigned to one or more networks; assigning/removing is an
 * explicit control-plane operation (the Addon "Tailnet-Netze" group tab).
 *
 * `deployment`/`deploymentEndpoint` (ObjectBase) and `deploymentRunner` (Links)
 * were dropped — they belonged to the members runtime layer (20260907-runner-companion).
 */
export const migrate = async ({ query }) => {
    await query('SET @@system_versioning_alter_history = 1', []);
    await query(`
        ALTER TABLE ObjectBase
        MODIFY COLUMN \`Type\` enum('user','person','guest','extern','group','ggroup','family','historic','list','dlist','email','entry','visible','changeable','include','exclude','intersect','job','function','achievement','achievementT','action','actionT','event','eventT','eventFunctionT','eventJob','eventJobT','location','locationT','locationC','gentry','account','fiscalyear','costcenter','document','accountingVisible','accountingChangeable','project','repositoryShare','directoryShare','runner','tailnet') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL
    `, []);
    await query(`
        ALTER TABLE Links
        MODIFY COLUMN \`Type\` enum(
            'member','memberA','member0','memberSys','function','filter','list','dynamic',
            'config','achievement','identifyer','admin','action','event',
            'transaction','transactionLine','txReference','location','family','familyFees',
            'memberS','locationC','locationT','memberGA','actionT','portal_pending',
            'projectShare','tailnetRunner'
        ) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL
    `, []);
    await query('SET @@system_versioning_alter_history = 0', []);
};