Skip to content

Deploy definitions with CI/CD

Use this page to move the definitions of a feature store from one environment to another in a reviewed, repeatable way: from a pull request, through an integration environment (INT), a user acceptance environment (UAT) and production (PRD), with an approval step before each one.

Use From prototype to production instead when you copy work once, by hand, between two stores. Use the migration for a one-off promotion of a lab; use this page when the work must be deployed again and again from files under version control.

The principle: definitions are deployed, state is not

Deployed (the bundle holds them) Never deployed (each environment computes its own)
Processes: the view SQL and the process options Feature values (the FS_T_* tables)
Datasets: the frozen selection of features and versions The run history (FS_FOLLOW_UP)
Upstream, downstream and attached views The vector index
Manager structure (TimeManager and FilterManager views and tables) The dates and segments of the managers (unless you bundle them, see Back up a data domain)
Data-domain clocks and settings Anything in an environment that a run wrote
Documentation, glossary, feature properties, physical storage characteristics
The objects of other databases the bundle needs (requires), checked on the target and never created

Consequences:

  • A process is named by its view, never by its process id. Ids differ from one installation to the next.
  • Databases are written as variables ({{FS_DB}}, {{FS_VIEW_DB}}, ...). Each environment file gives their values.
  • Each environment computes its own history. After a deployment, the values come from a compute step, not from the bundle.

The bundle

export_definitions writes this tree (deterministic: the same store gives the same files):

deployment/
  manifest.yaml              version that exported it, source, variables, objects in deployment order, a fingerprint per file
  definitions/
    table_<name>.yaml        storage tables that must exist before the views
    view_<name>.yaml         upstream and downstream views, attached views
    manager_<name>.yaml      TimeManager and FilterManager structure
    process_<name>.yaml      process view SQL, options, storage placement
    dataset_<name>.yaml      dataset selection (features and versions)
    domain_<name>.yaml       data-domain clock and settings
    glossary.yaml            glossary terms of the exported domains
    documentation/<name>.yaml
    requires_<name>.yaml     objects of other databases the bundle needs (checked, not created)
  environments/
    example.yaml             one file per environment: connection, variables, domain map, options
  conflict_policy.yaml       what to do with each object, by situation on the target
  deploy.py                  plan, apply, compute
  requirements.txt           tdfs4ds (this version) and pyyaml
  env.example                the session settings as a .env template, secrets as placeholders
  README.md                  what the bundle holds and how to deploy it
  report.html                the migration-style report of the export

Copy environments/example.yaml once per environment (int.yaml, uat.yaml, prd.yaml). Commit the bundle and the environment files. Never commit a secret.

The four functions

All four are top-level functions of tdfs4ds. pyyaml is imported only by them, so import tdfs4ds does not load it.

1. Export the definitions

import tdfs4ds

out = tdfs4ds.export_definitions(
    'deployment',                      # folder of the bundle (created)
    data_domains=['MY_DOMAIN'],        # or seeds=['<process view>', ...]; None with None = the whole store
    include_downstream=True,           # also the views that read the exported objects
    outside_objects='keep',            # 'keep' (default): listed as requirements; 'move': created by the bundle
)
print(out['objects'], out['by_kind'], out['errors'])

export_definitions only reads the source store. Use source='<OTHER_STORE>' to export a store that is not the active one (it must be readable from this system).

Exporting again into the same folder rewrites every file of the bundle except conflict_policy.yaml: it holds the reviewer's decisions (replace, skip) and is kept as it is. Delete it to get the default policy back.

2. Plan the deployment on an environment (read only)

plan = tdfs4ds.plan_deployment('deployment', 'deployment/environments/int.yaml')
plan.save('plans/int.plan.json')
plan.report('plans/int.plan.md', fmt='md')
print(plan.summary())
print(plan.has_unresolved_conflicts)   # True when a decision of the policy is 'fail'

plan_deployment compares each definition with the target store (the active session) and gives one of five situations: create (absent), identical (the same fingerprint), different (another definition under the same name), unavailable (a required object of another database is missing), to_initialise (a manager exists and is empty). The conflict policy turns each situation into a decision: create, skip, replace or fail. A plan holding a fail cannot be applied.

The plan also lists the GRANTs between databases that the apply needs: a view is resolved with the rights of the database that holds it, so each target view database needs SELECT ... WITH GRANT OPTION on what its views read in another database (the source tables the bundle requires, the store's tables for a dataset). Without them the apply fails with Error 3523 or 5315 after part of the bundle was registered. The plan reads the rights in DBC and reports each grant as granted, missing or not verified (rights the session cannot read), in the plan report and as a warning. It never blocks the plan and tdfs4ds never runs a GRANT: a DBA does, then the apply goes ahead.

3. Apply the plan (writes the target)

result = tdfs4ds.apply_deployment(
    tdfs4ds.load_plan('plans/int.plan.json'),
    'deployment/environments/int.yaml',
    out_dir='plans',
)
print(result.summary())

apply_deployment runs the actions in dependency order: tables, upstream views, managers, processes, domain clocks and settings, datasets, downstream views, glossary, documentation. It registers the processes and never runs them (run_now=False). It refuses (TargetChangedError) when the target changed since the plan. The first failure stops the run and is reported with its whole database error. It writes apply.json, apply.md, managers_to_initialise.json and run_order.json to out_dir.

Use dry_run=True to list the actions without writing anything.

4. Compute (optional, separate step)

res = tdfs4ds.compute_deployment(
    tdfs4ds.load_plan('plans/int.plan.json'),
    'deployment/environments/int.yaml',
    changed=False,        # True: only what changed (force_compute='changed')
    initialise=True,      # fill the empty managers first
)
print(res['summary'])

compute_deployment fills the empty managers the bundle can fill: bundled contents first, else a TimeManager whose calendar rule and first date are in the bundle (its dates are generated). A manager that holds rows is never touched. Then it computes the processes, per data domain: a domain with a clock is rolled out from its first date (roll_out(..., time_id_start=1, on_failure='raise', check_upstream=True)), a domain without one runs its processes. Processes whose manager is still empty are skipped and listed.

By default a calendar rule generates dates up to now. until='bundle' (--until bundle in deploy.py) stops at the source's last date instead:

res = tdfs4ds.compute_deployment(plan, 'deployment/environments/int.yaml', until='bundle')

A new process: compute its history first. A plain run() of a newly deployed process computes only the current date of its clock. A history is built forward only, so a later roll_out over the earlier dates is then refused (the stored values start after the first date). Use compute (or roll_out(data_domain=..., time_id_start=1)) for a new process; if run() came first, rebuild its history with roll_out([process], rebuild_history=True).

Compute is kept apart from apply on purpose: a deployment can be reviewed before any value is computed, and a large history can run in its own job or be left to your own orchestrator (which reads run_order.json).

Write the bundle as a zip

tdfs4ds.write_deployment_bundle('deployment.zip', data_domains=['MY_DOMAIN'])

The archive has sorted entries with a fixed date, so the same export gives the same content. The app offers the same download for the staged plan of the Migration panel.

The environment file

name: int
connection:
  host: my-teradata-host.example.com
  logmech: TD2
  username: ${TD_USERNAME}          # read from the process environment (CI secret store)
  password: ${TD_PASSWORD}
  encrypt: true
variables:
  FS_DB: INT_FS
  FS_VIEW_DB: INT_FS_VIEWS
  SOURCE_DB: INT_SOURCE
domain_map:
  MY_DOMAIN: MY_DOMAIN_INT          # data domain of the bundle -> data domain in this environment
options:
  rebuild_lineage: true
  statistics: true
  build_vector_index: false
  • ${NAME} is expanded from the process environment. A missing value fails the plan (it names the variable).
  • variables gives the database of each variable in this environment. A variable missing here fails the plan.
  • domain_map renames data domains. Omit a domain to keep its name.
  • The connection can also come from a .env file: deploy.py plan --env-file .env opens the session with tdfs4ds.open_session.

The conflict policy

conflict_policy.yaml is read from the bundle. The defaults are:

defaults:
  create: create          # absent on the target: create it
  identical: skip         # same fingerprint: nothing to do
  different: fail         # another definition under the same name: decide
  unavailable: fail       # a required object of another database is missing
  to_initialise: skip     # empty manager: computed by compute_deployment
kinds:
  documentation:
    different: replace    # documentation may be replaced by the reviewed text
objects:
  process:INT_FS_VIEWS.MY_PROCESS_VIEW: replace   # one object, by key (as listed in plan.md)

Decisions are create, skip, replace or fail. A fail stops the plan (exit code 1) until it is decided. A time or filter manager is never replaced (its contents would be lost): a replace on a manager becomes fail.

deploy.py: commands and exit codes

python deploy.py plan    --env environments/int.yaml [--out plans]
python deploy.py apply   --env environments/int.yaml --plan plans/int.plan.json [--dry-run]
python deploy.py compute --env environments/int.yaml [--changed] [--until bundle]
Command Exit code 0 Exit code 1 Exit code 2
plan no unresolved conflict a fail decision or an unavailable object
apply every action done or already deployed an action failed (see apply.md) the target changed since the plan: plan again
compute everything computed a failure (listed in the output)

Options: --env-file (a .env with the connection, instead of the environment file's connection), --definitions (the bundle folder, default: the folder of deploy.py), --out (where plans and reports go).

The CI/CD flow

  1. Export from the source store, then open a pull request with the exported files (or edit them by hand and review the diff).
  2. Plan on INT in CI: python deploy.py plan --env environments/int.yaml --out plans. Publish plans/int.plan.md with the pull request.
  3. Review the plan. Resolve every fail in conflict_policy.yaml (replace or skip). Merge.
  4. Apply on INT: python deploy.py apply --env environments/int.yaml --plan plans/int.plan.json.
  5. Compute on INT: python deploy.py compute --env environments/int.yaml (or your own orchestrator, in the order of run_order.json).
  6. Promote to UAT, then PRD: the same files with the next environment file. Put each one behind an approval step: plan, review the plan, apply, compute.

A generic CI job

GitHub Actions syntax. The job names and secret names are examples. Secrets come from the CI secret store.

name: deploy-features
on:
  pull_request:
  push:
    branches: [main]
jobs:
  plan-int:
    runs-on: ubuntu-latest
    env:
      TD_USERNAME: ${{ secrets.INT_TD_USERNAME }}
      TD_PASSWORD: ${{ secrets.INT_TD_PASSWORD }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - run: pip install -r deployment/requirements.txt
      - run: python deployment/deploy.py plan --env deployment/environments/int.yaml --out plans
      - uses: actions/upload-artifact@v4
        with:
          name: plan-int
          path: plans/
  apply-int:
    if: github.ref == 'refs/heads/main'
    needs: plan-int
    runs-on: ubuntu-latest
    environment: int               # an approval gate on the environment
    env:
      TD_USERNAME: ${{ secrets.INT_TD_USERNAME }}
      TD_PASSWORD: ${{ secrets.INT_TD_PASSWORD }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - run: pip install -r deployment/requirements.txt
      - run: python deployment/deploy.py plan --env deployment/environments/int.yaml --out plans
      - run: python deployment/deploy.py apply --env deployment/environments/int.yaml --plan plans/int.plan.json --out plans

The plan is made again in the apply job, so the apply always checks the target as it is at that moment. Exit code 2 from apply means the target changed in between: the job fails, and the plan is made again.

Same system or another system

  • Same system (the source store and the target are on one system): run the functions in one session. Export with source='<SOURCE_STORE>', then plan_deployment and apply_deployment against the active store.
  • Another system (a lab on one system, production on another): export on the source system, commit the folder, and run deploy.py plan and deploy.py apply against the target system from CI. The bundle carries no secret and no value, only definitions.

Back up a data domain

A backup keeps the definitions and the contents of the managers (their dates and segments):

tdfs4ds.export_definitions('backup_MY_DOMAIN', data_domains=['MY_DOMAIN'], with_manager_contents=True)

A deployment loads the bundled contents only into a manager that is absent or empty on the target. It never overwrites a manager that holds rows. Feature values are not in a backup: recompute them after a restore with compute_deployment or roll_out(..., force_compute=True).

After a failure

apply stops at the first failing action and writes apply.md: the failing action, the whole database error and the actions not done. Fix the cause, then run apply again with the same plan. The objects already deployed are recognised as identical and skipped, so the run resumes where it stopped. A second apply of a deployed plan does nothing.

If someone changed the target since the plan, apply refuses (exit code 2). Plan again.

Roll back

A deployment has no undo. To go back:

  1. Check out the previous commit's files of the bundle.
  2. Set different: replace for the objects concerned in conflict_policy.yaml (managers cannot be replaced: see above).
  3. Run plan, review it, then apply.

Feature values are not rolled back. Recompute the affected history with compute_deployment(..., changed=True) or roll_out(..., time_id_start=1, force_compute=True).

What a deployment reproduces

A deployment was checked end to end through a git clone, on the same system and on another system. With with_manager_contents=True, the target was equal to the source on every compared item, and the feature values were equal. Details:

  • A TimeManager with a previous-date view gets its <view>_PREVIOUS at apply.
  • Documentation provenance (MANUAL, IMPORTED, PROPAGATED, GENERATED) and the glossary source are kept.
  • Feature properties are written. Attached views are attached.
  • The dataset column order and the offset strategy are kept.
  • Each deploy.py run refreshes the store's FS_V_* catalog views (connect()). It does not touch workflow objects.

Two cases need care:

  • Outside objects. Objects read by downstream views, in other databases, are listed in requires. Data never travels: create the source tables on the target first. plan exits with code 1 (unavailable) while they are missing.
  • FilterManager. Without with_manager_contents=True, a FilterManager process is not computed on the target, because its manager is empty. Bundle the contents to reproduce segmented processes.

Compare two stores

tdfs4ds.deploy.fidelity compares two stores:

from tdfs4ds.deploy import fidelity
src = fidelity.workflow_snapshot('<SOURCE_STORE>', ['<SOURCE_DB>'])
tgt = fidelity.workflow_snapshot('<TARGET_STORE>', ['<TARGET_DB>'])
db_vars = {'<SOURCE_DB>': 'DB', '<TARGET_DB>': 'DB'}   # both names map to one variable
src_n = fidelity.normalise_snapshot(src, db_vars)
tgt_n = fidelity.normalise_snapshot(tgt, db_vars)
print(fidelity.render_comparison(fidelity.compare_snapshots(src_n, tgt_n)))

By design the bundle does not carry the follow-up, the EXPLAIN documentation, the finding acceptances, the execution resources, the logs, the FS_R_ tables and the vector index. The comparison does not expect them.

What is never migrated

  • Feature values, the run history, the vector index.
  • Managers' dates and segments, unless the bundle was made with with_manager_contents=True and the target manager is empty.
  • Objects of other databases: they are listed as requires and checked on the target. They are created only when you exported with outside_objects='move'.
  • Anything a run wrote in an environment.

Limits

  • A removed object is reported, not dropped. Removing an object from the bundle does not remove it from the target; use Remove objects for that.
  • apply registers processes but does not run them. The first values come from compute_deployment or your orchestrator.
  • The plan reads the target through the active session: run it as a user that can read the catalogs of the target.
  • A manager that holds rows is not changed by a deployment. Its structure is compared, its contents are not.

Before you go to production, check

  • The plan for PRD has no fail, and every replace is one you reviewed.
  • apply on UAT ran with exit code 0, and compute reproduced the values of INT for a few entities and dates.
  • The sanity checks (Workflow health) pass on the target.

See also