# Variable tenant

tenant: {
copy_tenant_template: (
tenant_template: {
loadAndSaveNewPlugin: (plugin: Plugin) => void;
target: string;
tenant_template: string;
},
) => Promise<void>;
create_tenant: (
t: {
loadAndSaveNewPlugin: (plugin: Plugin) => void;
noSignalOrDB?: boolean;
plugin_loader: Function;
t: string;
tenant_template?: string;
},
) => Promise<void>;
deleteTenant: (sub: string) => Promise<void>;
domain_sanitize: (s: string) => string;
eachTenant: (f: () => Promise<any>) => Promise<void>;
getAllTenantRows: () => Promise<Row[]>;
getAllTenants: () => Promise<string[]>;
insertTenant: (
subdomain: string,
email?: string,
description?: string,
template?: string,
) => Promise<string>;
switchToTenant: (domain: string, newurl: string) => Promise<void>;
Tenant: typeof Tenant;
upgrade_all_tenants_plugins: (
loadPlugin: (
arg0: Plugin,
arg1: boolean,
arg2: boolean,
) => Promise<{ version: string }>,
) => Promise<void>;
}

#### Type Declaration

- ##### copy_tenant_template: (
  tenant_template: {
  loadAndSaveNewPlugin: (plugin: Plugin) => void;
  target: string;
  tenant_template: string;
  },
  ) => Promise<void>

  Copy template data into tenant (target)

  - create backup from template tenant
  - restore backup to target tenant
  - clean up user_id in files
  - delete users (including sequence reset)

- ##### create_tenant: (
  t: {
  loadAndSaveNewPlugin: (plugin: Plugin) => void;
  noSignalOrDB?: boolean;
  plugin_loader: Function;
  t: string;
  tenant_template?: string;
  },
  ) => Promise<void>

  Create tenant? Not sure that is correct name

  - load plugins
  - use tenant template (copy structures from...)

- ##### `Function` deleteTenant: (sub: string) => Promise<void>

  Delete Tenant Note! This is deleting all tenant data in database!

  - drop database schema
  - delete information about tenant from main site

- ##### `Function` domain_sanitize: (s: string) => string

  Sanitize Domain (Normalize domain name).

  - force to lower case
  - remove . in name

- ##### eachTenant: (f: () => Promise<any>) => Promise<void>

  Call function f for each Tenant

- ##### `Function` getAllTenantRows: () => Promise<Row[]>

  List all Tenants

- ##### `Function` getAllTenants: () => Promise<string[]>

  List all Tenants

- ##### `Function` insertTenant: (
  subdomain: string,
  email?: string,
  description?: string,
  template?: string,
  ) => Promise<string>

  Insert Tenant

  - normalize domain name
  - create db schema
  - reset db schema (create required )

- ##### switchToTenant: (domain: string, newurl: string) => Promise<void>

  Switch to Tenant:

  - change current base_url

- ##### Tenant: typeof Tenant

- ##### upgrade_all_tenants_plugins: (
  loadPlugin: (
  arg0: Plugin,
  arg1: boolean,
  arg2: boolean,
  ) => Promise<{ version: string }>,
  ) => Promise<void>

- Defined in models/tenant.ts:346