Skip to content

Commit 67063ca

Browse files
authored
Merge pull request #48 from lightdash/new-rename-guide
rename docs
2 parents 3fd66d7 + 0d38545 commit 67063ca

6 files changed

+162
-13
lines changed

guides/renaming-models-and-fields.mdx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: "Renaming models, metrics, and dimensions"
3+
---
4+
5+
This guide explains two workflows that can be used to rename metrics, dimensions, or models across your entire project. All field or model references will be updated across charts, dashboards, and scheduled deliveries. This feature is particularly useful when you need to standardize naming conventions or fix typos.
6+
7+
<Info>
8+
Most content can also be renamed using [Dashboards as code](/references/dashboards-as-code), however, the rename methods in this doc require fewer steps and will automatically respect the right syntax for different field types. More importantly, it will update some content that is not exposed on Dashboards as code, like scheduled delivery filters.
9+
10+
Chart names and descriptions will not be updated using these rename workflows. If you want to update those in bulk, we recommend using Dashboards as code.
11+
</Info>
12+
13+
14+
## Rename in Lightdash
15+
16+
If you change field or table names in dbt, you will notice validation errors in your charts that use those fields or tables. You can fix these directly on the validation page by renaming references in the broken charts. You can easily access the validation page by clicking on the bell on the navigation bar.
17+
18+
<img
19+
src="/images/rename-validation-errors.png"
20+
alt="rename validation errors"
21+
className="mx-auto"
22+
style={{ width:"50%" }}
23+
/>
24+
25+
On the navigation page, hover over the chart you want to fix, and click on the **Fix** button.
26+
27+
![rename fix button](/images/rename_fix_button.png)
28+
29+
A popup menu will appear, where you can choose to rename a field or model using an **existing** value.
30+
31+
<img
32+
src="/images/rename_modal.png"
33+
alt="rename modal"
34+
className="mx-auto"
35+
style={{ width:"50%" }}
36+
/>
37+
38+
Optionally, you can click **Fix all ocurrences** to rename the same field or table on all content, including other charts, dashboards and scheduled deliveries.
39+
40+
If you have made mulitple field or table changes to the same chart (eg: you changed 2 metrics), you will have to perform multiple rename actions.
41+
42+
After renaming, consider running validation again to ensure everything works as expected.
43+
44+
45+
## Rename in the CLI
46+
47+
The Lightdash CLI provides an alternative and more flexible way to rename models or fields across your project. This is a more advanced option to the UI and affects all the content in the project. The CLI will also allow you to rename content before changes happen to dbt.
48+
49+
50+
### Important CLI callouts
51+
52+
- Renaming is project-wide by default, but can be scoped to a specific model using the `--model` option.
53+
- Always use `--dry-run` first to understand the impact of your changes.
54+
- You can use `--list` on your actual run to get a full list of everything that was updated.
55+
- Only lowercase letters (a-z) and underscores `_` are allowed in field and table names.
56+
57+
58+
### Example CLI Workflow
59+
60+
This is a sample of how you can take the most from this feature, when renaminig content on your dbt project.
61+
62+
1. Rename a field in your dbt project YML file: `user_id` becomes `customer_id`.
63+
2. Create a preview environment to test those changes.
64+
3. Existing charts will fail, you can go into validation to confirm which ones are affected.
65+
4. Run `lightdash rename --type field --from user_id --to customer_id -p <preview-project-id> --dry-run` to list the affected charts.
66+
5. If you are happy with the changes, run rename without `--dry-run`.
67+
6. Confirm all charts are referencing new fields (they might still error if you haven't updated your warehouses using dbt run).
68+
7. Merge the code, run dbt, then run `lightdash rename --type field --from user_id --to customer_id -p <production-project-id> --list` on your main project.
69+
- The `--list` option gives you a full list of content that was changed.
70+
71+
The CLI will show you which charts, dashboards, alerts, and dashboard schedulers will be updated and also, we will generate a JSON log that contains the affected chart and dashboard names and UUIDs, you can use those UUIDs to manually revert some of the charts to a previous version.
72+
73+
![rename CLI list](/images/rename_cli_list.png)
74+
75+
[Read the CLI reference doc](/references/lightdash-cli#lightdash-rename) for all arguments and more examples.
76+
77+
78+
## Reverting changes
79+
80+
When renaming, a new chart version is created with the new changes. If you made a mistake renaming, you could run rename again, or you could restore individual charts using [version history](https://docs.lightdash.com/guides/version-history#chart-version-history)

images/rename-validation-errors.png

11.6 KB
Loading

images/rename_cli_list.png

46.5 KB
Loading

images/rename_fix_button.png

31.2 KB
Loading

images/rename_modal.png

35.7 KB
Loading

references/lightdash-cli.mdx

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ description: "The Lightdash CLI is the recommended way to develop your Lightdash
55

66
## Dependencies
77

8-
The Lightdash CLI requires the [dbt core](https://docs.getdbt.com/docs/core/installation-overview) or the [dbt cloud CLI](https://docs.getdbt.com/docs/cloud/cloud-cli-installation) to be installed and available under the `dbt` command.
8+
The Lightdash CLI requires Node, NPM, and the [dbt core](https://docs.getdbt.com/docs/core/installation-overview) or [dbt cloud](https://docs.getdbt.com/docs/cloud/cloud-cli-installation) CLI to be installed and available under the `dbt` command.
99

10-
### Known limitations when using **dbt cloud CLI**
10+
### Known limitations when using dbt cloud CLI
1111

12-
#### Warehouse credentials dependency for some commands
12+
**Warehouse credentials dependency for some commands**
1313

1414
Affected commands: `lightdash generate`, `lightdash preview` and `lightdash start-preview`
1515

1616
These commands rely on the warehouse credentials from the active project, as the dbt Cloud CLI does not expose credentials directly. Ensure the project's credentials have access to all development and staging schemas for a seamless experience.
1717

18-
#### Empty warehouse credentials for new projects
18+
**Empty warehouse credentials for new projects**
1919

2020
Affected commands: `lightdash deploy --create`
2121

2222
When using this command to create a new project that is not a preview, the warehouse credentials will not be populated automatically. Users must update the warehouse credentials manually in the project settings page after the project is created.
2323

24+
2425
## Global options
2526

2627
There are three global options that can be used with any Lightdash CLI command: [version](#version), [help](#help), and [verbose](#verbose).
@@ -96,13 +97,13 @@ For examples and command-specific options, click through the command in the tabl
9697
|[`lightdash stop-preview`](/references/lightdash-cli#lightdash-stop-preview) | Shut down an open preview project |
9798
|[`lightdash deploy`](/references/lightdash-cli#lightdash-deploy) | Compile and deploy a Lightdash project using your local project and credentials |
9899
|[`lightdash refresh`](/references/lightdash-cli#lightdash-refresh) | Refresh Lightdash project with remote repository |
99-
|[`lightdash validate`](/references/lightdash-cli#lightdash-validate) | Validates content from your active project against your local project files |
100-
|[`lightdash generate`](/references/lightdash-cli#lightdash-generate) | Generates or updates schema.yml file(s) for the selected model(s) |
101-
|[`lightdash dbt run`](/references/lightdash-cli#lightdash-dbt-run) | Runs dbt and then generates or updates schema.yml file(s) for the selected model(s)|
102-
|[`lightdash generate-exposures`](/references/lightdash-cli#lightdash-generate-exposures) | [Experimental command] Generates a .yml file for Lightdash exposures |
103-
|[`lightdash download`](/references/lightdash-cli#lightdash-download) | Downloads all charts and dashboards from your Lightdash project as code |
104-
|[`lightdash upload`](/references/lightdash-cli#lightdash-upload) | Uploads all updates to charts and dashboards as code to your Lightdash project |
105-
100+
|[`lightdash validate`](/references/lightdash-cli#lightdash-validate) | Validate content from your active project against your local project files |
101+
|[`lightdash generate`](/references/lightdash-cli#lightdash-generate) | Generate or update `schema.yml` file(s) for the selected model(s) |
102+
|[`lightdash dbt run`](/references/lightdash-cli#lightdash-dbt-run) | Run dbt, then generate or update `schema.yml` file(s) for the selected model(s) |
103+
|[`lightdash generate-exposures`](/references/lightdash-cli#lightdash-generate-exposures) | [Experimental command] Generates a YAML file for Lightdash exposures |
104+
|[`lightdash download`](/references/lightdash-cli#lightdash-download) | Download all charts and dashboards from your Lightdash project as code |
105+
|[`lightdash upload`](/references/lightdash-cli#lightdash-upload) | Upload charts and dashboards as code to your Lightdash project |
106+
|[`lightdash rename`](/references/lightdash-cli#lightdash-rename) | Rename model or field names across all your Lightdash content |
106107
---
107108

108109
### `lightdash login`
@@ -365,6 +366,7 @@ All standard [dbt options](#dbt-options) work with `lightdash validate`.
365366
- (default: ["charts","dashboards","tables"])
366367
- Specify project elements to validate.
367368

369+
368370
**Example:**
369371

370372
Validate only dashboards and use the existing compiled dbt manifest:
@@ -373,12 +375,14 @@ Validate only dashboards and use the existing compiled dbt manifest:
373375
lightdash validate --only ["dashboards"] --skip-dbt-compile
374376
```
375377

378+
376379
### `lightdash generate`
377380

378381
Generates a new `schema.yml` file or updates existing `schema.yml` for selected model(s).
379382

380383
All standard [dbt options](#dbt-options) work with `lightdash generate`.
381384

385+
382386
**Options:**
383387

384388
- `-y` or `--assume-yes`
@@ -388,6 +392,7 @@ All standard [dbt options](#dbt-options) work with `lightdash generate`.
388392
- (default: false)
389393
- exclude Lightdash metadata from the generated .yml
390394

395+
391396
**Example:**
392397

393398
Generate or update YAML file for a single dbt model to cover all columns in the database:
@@ -408,6 +413,7 @@ Generates a `schema.yml` file for Lightdash exposures.
408413

409414
This command does not support using dbt options.
410415

416+
411417
**Options:**
412418

413419
- `--project-dir [path]`
@@ -416,6 +422,7 @@ This command does not support using dbt options.
416422
- `--output [path]`
417423
- The path where the output exposures YAML file will be written
418424

425+
419426
**Example:**
420427

421428
Create or update YAML file called `lightdash-exposures.yml` in the current directory with all exposures in Lightdash:
@@ -424,12 +431,14 @@ Create or update YAML file called `lightdash-exposures.yml` in the current direc
424431
lightdash generate-exposures --output ./lightdash-exposures.yml
425432
```
426433

434+
427435
### `lightdash dbt run`
428436

429437
Runs dbt and then generates or updates `schema.yml` file(s) for models that have columns missing or changed from the existing `schema.yml` files.
430438

431439
Any dbt option that works with `dbt run` will also work with `lightdash dbt run`. That includes all the [Lightdash dbt options](#dbt-options), and more ([see dbt run docs](https://docs.getdbt.com/reference/commands/run)).
432440

441+
433442
**Options:**
434443

435444
- `--exclude-meta`
@@ -440,14 +449,16 @@ Any dbt option that works with `dbt run` will also work with `lightdash dbt run`
440449
- `-no` or `--assume-no`
441450
- assume no to prompts (default: false)
442451

443-
**Examples:**
452+
453+
**Example:**
444454

445455
Run a single model and create or update its `schema.yml` file:
446456

447457
```bash
448458
lightdash dbt run --select mymodel
449459
```
450460

461+
451462
### `lightdash download`
452463

453464
Downloads all charts and dashboards from your Lightdash project as code. A `lightdash` directory is created in your working directory and all of the charts and dashboards are written there as .yml files.
@@ -456,6 +467,7 @@ E.g. if you're running this command inside your dbt directory (eg: `/home/javi/d
456467

457468
You can make changes to the code and upload these changes back to your Lightdash project. Content that's been downloaded as code can still be managed in the Lightdash UI.
458469

470+
459471
**Options:**
460472

461473
- `--charts` or `-c`
@@ -467,6 +479,7 @@ You can make changes to the code and upload these changes back to your Lightdash
467479
- `--project <project uuid>`
468480
- download all charts and dashboards from a specific project. You can find the project UUID for a project from a Lightdash URL. E.g. here, the project UUID is `123-project-uuid` `https://app.lightdash.cloud/projects/123-project-uuid/`
469481

482+
470483
**Examples:**
471484

472485
Download all charts and dashboards from your project.
@@ -478,7 +491,7 @@ lightdash download
478491
Download a specific dashboard from your Lightdash project.
479492

480493
```bash
481-
lightdash upload -d https://app.lightdash.cloud/my-dashboard-url
494+
lightdash download -d https://app.lightdash.cloud/my-dashboard-url
482495
```
483496

484497
Download all content from a project to the directory `/Users/katiehindson/lightdash/lightdash-analytics/`
@@ -507,6 +520,7 @@ Uploads charts and dashboards that you've made changes to from the `lightdash/`
507520

508521
If there have been changes made to a chart or dashboard in the application that is being uploaded from code, `lightdash upload` will overwrite the changes.
509522

523+
510524
**Options:**
511525

512526
- `--force`
@@ -520,6 +534,7 @@ If there have been changes made to a chart or dashboard in the application that
520534
- `--project <project uuid>`
521535
- upload all charts and dashboards from a specific project. You can find the project UUID for a project from a Lightdash URL. E.g. here, the project UUID is `123-project-uuid` `https://app.lightdash.cloud/projects/123-project-uuid/`
522536

537+
523538
**Examples:**
524539

525540
Upload all charts and dashboards in code from your `lightdash/` directory to your Lightdash project.
@@ -554,6 +569,60 @@ Upload all charts and dashboards from your `lightdash/` directory to a specific
554569
lightdash upload --project 21eef0b9-5bae-40f3-851e-9554588e71a6
555570
```
556571

572+
573+
### `lightdash rename`
574+
575+
Rename model or field names across all content in your Lightdash project. This command will do a full find and replace on a field or table so all references in chart fields, dashboard filters, table calculations, custom metrics, etc. can be changed at once.
576+
577+
578+
**Arguments:**
579+
580+
- `--type`
581+
- Specify what you're renaming
582+
- Accepted values: `field` or `model`
583+
- `--from`
584+
- The current name of the table or field you want to change (this is the slug from your YAML definition, i.e. `num_users`)
585+
- `--to`
586+
- The new name you want to use (must match the new slug in your YAML for this field or table, i.e. `count_distinct_user_id`)
587+
588+
589+
**Options:**
590+
591+
- `--project`, `-p`
592+
- Project UUID to target a specific project.
593+
- (default: The most recent project you set with `lightdash config set-project`)
594+
- `--model`, `-m`
595+
- The model to target for field renaming. This is only needed if the current field name is not unique in your project.
596+
- `--dry-run`
597+
- List all content the rename action will change, no changes will be made.
598+
- `--list`
599+
- List all charts and dashboards that were renamed after the command is complete.
600+
- `--assume-yes`, `-y`
601+
- Assume yes to all prompts.
602+
603+
604+
**Examples:**
605+
606+
Rename the field `num_users` to `count_distinct_user_id`.
607+
608+
```bash
609+
lightdash rename --type field --from num_users --to count_distinct_user_id
610+
```
611+
612+
Do a dry run of changing the table reference from `users_mart_v1` to `users`.
613+
614+
```bash
615+
lightdash rename --type model --from users_mart_v1 --to users --dry-run
616+
```
617+
618+
Rename the field `count` to `count_distinct_order_id` in the `orders` model and list all affected content when complete:
619+
620+
```bash
621+
lightdash rename --type field --model orders --from count --to count_distinct_order_id --list
622+
```
623+
624+
---
625+
557626
## dbt options
558627

559628
These are options from the dbt Core CLI that also work with some Lightdash CLI commands.

0 commit comments

Comments
 (0)