You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
+

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)
Copy file name to clipboardExpand all lines: references/lightdash-cli.mdx
+82-13Lines changed: 82 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -5,22 +5,23 @@ description: "The Lightdash CLI is the recommended way to develop your Lightdash
5
5
6
6
## Dependencies
7
7
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.
9
9
10
-
### Known limitations when using **dbt cloud CLI**
10
+
### Known limitations when using dbt cloud CLI
11
11
12
-
#### Warehouse credentials dependency for some commands
12
+
**Warehouse credentials dependency for some commands**
13
13
14
14
Affected commands: `lightdash generate`, `lightdash preview` and `lightdash start-preview`
15
15
16
16
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.
17
17
18
-
#### Empty warehouse credentials for new projects
18
+
**Empty warehouse credentials for new projects**
19
19
20
20
Affected commands: `lightdash deploy --create`
21
21
22
22
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.
23
23
24
+
24
25
## Global options
25
26
26
27
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
96
97
|[`lightdash stop-preview`](/references/lightdash-cli#lightdash-stop-preview)| Shut down an open preview project |
97
98
|[`lightdash deploy`](/references/lightdash-cli#lightdash-deploy)| Compile and deploy a Lightdash project using your local project and credentials |
98
99
|[`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 |
106
107
---
107
108
108
109
### `lightdash login`
@@ -365,6 +366,7 @@ All standard [dbt options](#dbt-options) work with `lightdash validate`.
365
366
- (default: ["charts","dashboards","tables"])
366
367
- Specify project elements to validate.
367
368
369
+
368
370
**Example:**
369
371
370
372
Validate only dashboards and use the existing compiled dbt manifest:
@@ -373,12 +375,14 @@ Validate only dashboards and use the existing compiled dbt manifest:
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.
430
438
431
439
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)).
432
440
441
+
433
442
**Options:**
434
443
435
444
-`--exclude-meta`
@@ -440,14 +449,16 @@ Any dbt option that works with `dbt run` will also work with `lightdash dbt run`
440
449
-`-no` or `--assume-no`
441
450
- assume no to prompts (default: false)
442
451
443
-
**Examples:**
452
+
453
+
**Example:**
444
454
445
455
Run a single model and create or update its `schema.yml` file:
446
456
447
457
```bash
448
458
lightdash dbt run --select mymodel
449
459
```
450
460
461
+
451
462
### `lightdash download`
452
463
453
464
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
456
467
457
468
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.
458
469
470
+
459
471
**Options:**
460
472
461
473
-`--charts` or `-c`
@@ -467,6 +479,7 @@ You can make changes to the code and upload these changes back to your Lightdash
467
479
-`--project <project uuid>`
468
480
- 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/`
469
481
482
+
470
483
**Examples:**
471
484
472
485
Download all charts and dashboards from your project.
@@ -478,7 +491,7 @@ lightdash download
478
491
Download a specific dashboard from your Lightdash project.
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/`
507
520
508
521
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.
509
522
523
+
510
524
**Options:**
511
525
512
526
-`--force`
@@ -520,6 +534,7 @@ If there have been changes made to a chart or dashboard in the application that
520
534
-`--project <project uuid>`
521
535
- 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/`
522
536
537
+
523
538
**Examples:**
524
539
525
540
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
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:
0 commit comments