Skip to content

Commit a77ab44

Browse files
authored
chore: put primary keys on top in model files (#6861)
1 parent 7bfeda1 commit a77ab44

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

packages/cubejs-schema-compiler/src/scaffolding/formatters/BaseSchemaFormatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export abstract class BaseSchemaFormatter {
121121
: {
122122
sql: `SELECT * FROM ${table}`,
123123
};
124-
124+
125125
return {
126126
cube: tableSchema.cube,
127127
...sqlOption,
@@ -139,7 +139,7 @@ export abstract class BaseSchemaFormatter {
139139
},
140140
}))
141141
.reduce((a, b) => ({ ...a, ...b }), {}),
142-
dimensions: tableSchema.dimensions
142+
dimensions: tableSchema.dimensions.sort((a) => (a.isPrimaryKey ? -1 : 0))
143143
.map((m) => ({
144144
[this.memberName(m)]: {
145145
sql: this.sqlForMember(m),

packages/cubejs-server-core/src/core/DevServer.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,35 @@ export class DevServer {
166166
await fs.emptyDir(path.join(schemaPath, 'cubes'));
167167
await fs.emptyDir(path.join(schemaPath, 'views'));
168168

169-
await fs.writeFile(path.join(schemaPath, 'views', '.gitkeep'), '');
169+
await fs.writeFile(path.join(schemaPath, 'views', 'example_view.yml'), `# In Cube, views are used to expose slices of your data graph and act as data marts.
170+
# You can control which measures and dimensions are exposed to BIs or data apps,
171+
# as well as the direction of joins between the exposed cubes.
172+
# You can learn more about views in documentation here - https://cube.dev/docs/schema/reference/view
173+
174+
175+
# The following example shows a view defined on top of orders and customers cubes.
176+
# Both orders and customers cubes are exposed using the "includes" parameter to
177+
# control which measures and dimensions are exposed.
178+
# Prefixes can also be applied when exposing measures or dimensions.
179+
# In this case, the customers' city dimension is prefixed with the cube name,
180+
# resulting in "customers_city" when querying the view.
181+
182+
# views:
183+
# - name: example_view
184+
#
185+
# cubes:
186+
# - join_path: orders
187+
# includes:
188+
# - status
189+
# - created_date
190+
#
191+
# - total_amount
192+
# - count
193+
#
194+
# - join_path: orders.customers
195+
# prefix: true
196+
# includes:
197+
# - city`);
170198
await Promise.all(files.map(file => fs.writeFile(path.join(schemaPath, 'cubes', file.fileName), file.content)));
171199

172200
res.json({ files });

0 commit comments

Comments
 (0)