@lightdash/cli 0.2031.0 → 0.2031.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { DbtDoc, DbtModelNode, DbtSchemaEditor } from '@lightdash/common';
1
+ import { DbtDoc, DbtModelNode, DbtSchemaEditor, SupportedDbtVersions } from '@lightdash/common';
2
2
  import { WarehouseClient, WarehouseTableSchema } from '@lightdash/warehouses';
3
3
  type CompiledModel = {
4
4
  name: string;
@@ -24,8 +24,9 @@ type FindAndUpdateModelYamlArgs = {
24
24
  projectDir: string;
25
25
  projectName: string;
26
26
  assumeYes: boolean;
27
+ dbtVersion?: SupportedDbtVersions;
27
28
  };
28
- export declare const findAndUpdateModelYaml: ({ model, table, docs, includeMeta, projectDir, projectName, assumeYes, }: FindAndUpdateModelYamlArgs) => Promise<{
29
+ export declare const findAndUpdateModelYaml: ({ model, table, docs, includeMeta, projectDir, projectName, assumeYes, dbtVersion, }: FindAndUpdateModelYamlArgs) => Promise<{
29
30
  updatedYml: DbtSchemaEditor;
30
31
  outputFilePath: string;
31
32
  }>;
@@ -32,19 +32,26 @@ const getWarehouseTableForModel = async ({ model, warehouseClient, preserveColum
32
32
  }, {});
33
33
  };
34
34
  exports.getWarehouseTableForModel = getWarehouseTableForModel;
35
- const generateModelYml = ({ model, table, includeMeta, }) => ({
35
+ // Check if we should use dbt 1.10+ metadata structure
36
+ const wrapInConfig = (dbtVersion, meta) => {
37
+ const useDbt110Metadata = dbtVersion &&
38
+ Object.values(common_1.SupportedDbtVersions).indexOf(dbtVersion) >=
39
+ Object.values(common_1.SupportedDbtVersions).indexOf(common_1.SupportedDbtVersions.V1_10);
40
+ return useDbt110Metadata ? { config: { meta } } : { meta };
41
+ };
42
+ const generateModelYml = ({ model, table, includeMeta, dbtVersion, }) => ({
36
43
  name: model.name,
37
44
  columns: Object.entries(table).map(([columnName, dimensionType]) => ({
38
45
  name: columnName,
39
46
  description: '',
40
47
  ...(includeMeta
41
- ? {
48
+ ? wrapInConfig(dbtVersion, {
42
49
  meta: {
43
50
  dimension: {
44
51
  type: dimensionType,
45
52
  },
46
53
  },
47
- }
54
+ })
48
55
  : {}),
49
56
  })),
50
57
  });
@@ -83,11 +90,12 @@ const askOverwriteDescription = async (columnName, existingDescription, newDescr
83
90
  return newDescription;
84
91
  return existingDescription;
85
92
  };
86
- const findAndUpdateModelYaml = async ({ model, table, docs, includeMeta, projectDir, projectName, assumeYes, }) => {
93
+ const findAndUpdateModelYaml = async ({ model, table, docs, includeMeta, projectDir, projectName, assumeYes, dbtVersion, }) => {
87
94
  const generatedModel = generateModelYml({
88
95
  model,
89
96
  table,
90
97
  includeMeta,
98
+ dbtVersion,
91
99
  });
92
100
  const filenames = [];
93
101
  const { patchPath, packageName } = model;
@@ -107,6 +115,7 @@ const findAndUpdateModelYaml = async ({ model, table, docs, includeMeta, project
107
115
  const match = await (0, schema_1.searchForModel)({
108
116
  modelName: model.name,
109
117
  filenames,
118
+ dbtVersion,
110
119
  });
111
120
  if (match) {
112
121
  const { schemaEditor } = match;
@@ -137,7 +146,7 @@ const findAndUpdateModelYaml = async ({ model, table, docs, includeMeta, project
137
146
  columnName: column.name,
138
147
  properties: {
139
148
  description,
140
- meta,
149
+ ...(meta ? wrapInConfig(dbtVersion, meta) : {}),
141
150
  },
142
151
  });
143
152
  }
@@ -176,7 +185,7 @@ const findAndUpdateModelYaml = async ({ model, table, docs, includeMeta, project
176
185
  };
177
186
  }
178
187
  return {
179
- updatedYml: new common_1.DbtSchemaEditor().addModel(generatedModel),
188
+ updatedYml: new common_1.DbtSchemaEditor('', '', dbtVersion).addModel(generatedModel),
180
189
  outputFilePath,
181
190
  };
182
191
  };
@@ -1,4 +1,4 @@
1
- import { DbtSchemaEditor, DimensionType } from '@lightdash/common';
1
+ import { DbtSchemaEditor, DimensionType, SupportedDbtVersions } from '@lightdash/common';
2
2
  type YamlColumnMeta = {
3
3
  dimension?: {
4
4
  type?: DimensionType;
@@ -21,8 +21,9 @@ export type YamlSchema = {
21
21
  type SearchForModelArgs = {
22
22
  modelName: string;
23
23
  filenames: string[];
24
+ dbtVersion?: SupportedDbtVersions;
24
25
  };
25
- export declare const searchForModel: ({ modelName, filenames, }: SearchForModelArgs) => Promise<{
26
+ export declare const searchForModel: ({ modelName, filenames, dbtVersion, }: SearchForModelArgs) => Promise<{
26
27
  schemaEditor: DbtSchemaEditor;
27
28
  filename: string;
28
29
  } | undefined>;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.searchForModel = void 0;
4
4
  const common_1 = require("@lightdash/common");
5
5
  const fs_1 = require("fs");
6
- const loadYamlSchema = async (path) => {
6
+ const loadYamlSchema = async (path, dbtVersion) => {
7
7
  try {
8
- return new common_1.DbtSchemaEditor(await fs_1.promises.readFile(path, 'utf8'));
8
+ return new common_1.DbtSchemaEditor(await fs_1.promises.readFile(path, 'utf8'), path, dbtVersion);
9
9
  }
10
10
  catch (e) {
11
11
  if (e instanceof common_1.ParseError) {
@@ -15,9 +15,9 @@ const loadYamlSchema = async (path) => {
15
15
  throw e;
16
16
  }
17
17
  };
18
- const findModelInYaml = async ({ filename, modelName, }) => {
18
+ const findModelInYaml = async ({ filename, modelName, dbtVersion, }) => {
19
19
  try {
20
- const schemaEditor = await loadYamlSchema(filename);
20
+ const schemaEditor = await loadYamlSchema(filename, dbtVersion);
21
21
  if (schemaEditor.findModelByName(modelName)) {
22
22
  return schemaEditor;
23
23
  }
@@ -30,9 +30,13 @@ const findModelInYaml = async ({ filename, modelName, }) => {
30
30
  throw e;
31
31
  }
32
32
  };
33
- const searchForModel = async ({ modelName, filenames, }) => {
33
+ const searchForModel = async ({ modelName, filenames, dbtVersion, }) => {
34
34
  for await (const filename of filenames) {
35
- const schemaEditor = await findModelInYaml({ filename, modelName });
35
+ const schemaEditor = await findModelInYaml({
36
+ filename,
37
+ modelName,
38
+ dbtVersion,
39
+ });
36
40
  if (schemaEditor) {
37
41
  return {
38
42
  schemaEditor,
@@ -79,6 +79,11 @@ const generateHandler = async (options) => {
79
79
  warehouseClient,
80
80
  preserveColumnCase: options.preserveColumnCase,
81
81
  });
82
+ // Resolve dbt version for metadata structure
83
+ const resolvedDbtVersion = dbtVersion.versionOption === common_1.DbtVersionOptionLatest.LATEST
84
+ ? (0, common_1.getLatestSupportDbtVersion)()
85
+ : dbtVersion.versionOption;
86
+ globalState_1.default.debug(`Using detected dbt version ${resolvedDbtVersion} for metadata structure`);
82
87
  const { updatedYml, outputFilePath } = await (0, models_1.findAndUpdateModelYaml)({
83
88
  model: compiledModel,
84
89
  table,
@@ -87,6 +92,7 @@ const generateHandler = async (options) => {
87
92
  projectDir: absoluteProjectPath,
88
93
  projectName: context.projectName,
89
94
  assumeYes: options.assumeYes,
95
+ dbtVersion: resolvedDbtVersion,
90
96
  });
91
97
  try {
92
98
  if (options.skipExisting) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/cli",
3
- "version": "0.2031.0",
3
+ "version": "0.2031.2",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "lightdash": "dist/index.js"
@@ -32,8 +32,8 @@
32
32
  "parse-node-version": "^2.0.0",
33
33
  "unique-names-generator": "^4.7.1",
34
34
  "uuid": "^11.0.3",
35
- "@lightdash/common": "0.2031.0",
36
- "@lightdash/warehouses": "0.2031.0"
35
+ "@lightdash/common": "0.2031.2",
36
+ "@lightdash/warehouses": "0.2031.2"
37
37
  },
38
38
  "description": "Lightdash CLI tool",
39
39
  "devDependencies": {