Skip to content

Commit a796c36

Browse files
committed
Merge branch 'release_4.6'
2 parents 6046f21 + a7330de commit a796c36

File tree

16 files changed

+697
-278
lines changed

16 files changed

+697
-278
lines changed

docs/SUMMARY.md

Lines changed: 248 additions & 243 deletions
Large diffs are not rendered by default.

docs/deployments/configuration.md

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ localStudio:
536536

537537
### `logging`
538538

539-
The `logging` section configures Harper logging across all Harper functionality. This includes standard text logging of application and database events as well as structured data logs of record changes. Logging of application/database events are logged in text format to the `~/hdb/log/hdb.log` file (or location specified by `logging.root`).
539+
The `logging` section configures Harper logging across all Harper functionality. This includes standard text logging of application and database events as well as structured data logs of record changes. Logging of application/database events are logged in text format to the `~/hdb/log/hdb.log` file (or location specified by `logging.root` or `logging.path`). Many of the logging configuration properties can be set and applied without a restart (are dynamically applied).
540540

541541
In addition, structured logging of data changes are also available:
542542

@@ -585,7 +585,7 @@ There exists a log level hierarchy in order as `trace`, `debug`, `info`, `warn`,
585585

586586
`console` - _Type_: boolean; _Default_: true
587587

588-
Controls whether console.log and other console.\* calls (as well as another JS components that writes to `process.stdout` and `process.stderr`) are logged to the log file. By default, these are logged to the log file, but this can be disabled.
588+
Controls whether console.log and other console.\* calls (as well as another JS components that writes to `process.stdout` and `process.stderr`) are logged to the log file. By default, these are not logged to the log file, but this can be enabled:
589589

590590
```yaml
591591
logging:
@@ -594,13 +594,22 @@ logging:
594594

595595
`root` - _Type_: string; _Default_: \<ROOTPATH>/log
596596

597-
The path where the log files will be written.
597+
The directory path where the log files will be written.
598598

599599
```yaml
600600
logging:
601601
root: ~/hdb/log
602602
```
603603

604+
`path` - _Type_: string; _Default_: \<ROOTPATH>/log/hdb.log
605+
606+
The file path where the log file will be written.
607+
608+
```yaml
609+
logging:
610+
root: ~/hdb/log/hdb.log
611+
```
612+
604613
`rotation`
605614

606615
Rotation provides the ability for a user to systematically rotate and archive the `hdb.log` file. To enable `interval` and/or `maxSize` must be set.
@@ -667,7 +676,70 @@ logging:
667676
logSuccessful: false
668677
```
669678

670-
---
679+
## Defining Separate Logging Configurations
680+
681+
Harper's logger supports defining multiple logging configurations for different components in the system. Each logging configuration can be assigned its own `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`. All logging defaults to the configuration of the "main" logger as configured above, but when logging is configured for different loggers, they will use their own configuration. Separate loggers can be defined:
682+
683+
`logging.external`
684+
685+
The `logging.external` section can be used to define logging for all external components that use the [`logger` API](../technical-details/reference/globals.md). For example:
686+
```yaml
687+
logging:
688+
external:
689+
level: warn
690+
path: ~/hdb/log/apps.log
691+
```
692+
693+
`http.logging`
694+
695+
This section defines log configuration for HTTP logging. By default, HTTP requests are not logged, but defining this section will enable HTTP logging. Note that there can be substantive overhead to logging all HTTP requests. In addition to the standard logging configuration, the `http.logging` section also allows the following configuration properties to be set:
696+
* `timing` - This will log timing information
697+
* `headers` - This will log the headers in each request (which can be very verbose)
698+
* `id` - This will assign a unique id to each request and log it in the entry for each request. This is assigned as the `request.requestId` property and can be used to by other logging to track a request.
699+
Note that the `level` will determine which HTTP requests are logged:
700+
* `info` (or more verbose) - All HTTP requests
701+
* `warn` - HTTP requests with a status code of 400 or above
702+
* `error` - HTTP requests with a status code of 500
703+
704+
For example:
705+
```yaml
706+
http:
707+
logging:
708+
timing: true
709+
level: info
710+
path: ~/hdb/log/http.log
711+
... rest of http config
712+
```
713+
714+
`authentication.logging`
715+
716+
This section defines log configuration for authentication. This takes the standard logging configuration options of `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`.
717+
718+
`mqtt.logging`
719+
720+
This section defines log configuration for MQTT. This takes the standard logging configuration options of `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`.
721+
722+
`replication.logging`
723+
724+
This section defines log configuration for replication. This takes the standard logging configuration options of `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`.
725+
726+
`tls.logging`
727+
728+
This section defines log configuration for TLS. This takes the standard logging configuration options of `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`.
729+
730+
`storage.logging`
731+
732+
This section defines log configuration for setting up and reading the database files. This takes the standard logging configuration options of `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`.
733+
734+
`storage.logging`
735+
736+
This section defines log configuration for setting up and reading the database files. This takes the standard logging configuration options of `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`.
737+
738+
`analytics.logging`
739+
740+
This section defines log configuration for analytics. This takes the standard logging configuration options of `path` (or `root`), `level`, `tag`, and flag to enable/disable logging to `stdStreams`.
741+
742+
***
671743

672744
### `authentication`
673745

docs/developers/applications/caching.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ThirdPartyAPI extends Resource {
3737
Next, we define this external data resource as the "source" for the caching table we defined above:
3838

3939
```javascript
40-
const { MyTable } = tables;
41-
MyTable.sourcedFrom(ThirdPartyAPI);
40+
const { MyCache } = tables;
41+
MyCache.sourcedFrom(ThirdPartyAPI);
4242
```
4343

4444
Now we have a fully configured and connected caching table. If you access data from `MyCache` (for example, through the REST API, like `/MyCache/some-id`), Harper will check to see if the requested entry is in the table and return it if it is available (and hasn't expired). If there is no entry, or it has expired (it is older than one hour in this case), it will go to the source, calling the `get()` method, which will then retrieve the requested entry. Once the entry is retrieved, it will be saved/cached in the caching table (for one hour based on our expiration time).
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Data Loader
2+
3+
The Data Loader is a built-in component that provides a reliable mechanism for loading data from JSON or YAML files into Harper tables as part of component deployment. This feature is particularly useful for ensuring specific records exist in your database when deploying components, such as seed data, configuration records, or initial application data.
4+
5+
## Configuration
6+
7+
To use the Data Loader, first specify your data files in the `config.yaml` in your component directory:
8+
9+
```yaml
10+
dataLoader:
11+
files: 'data/*.json'
12+
```
13+
14+
The Data Loader is an [Extension](../components/reference.md#extensions) and supports the standard `files` configuration option.
15+
16+
## Data File Format
17+
18+
Data files can be structured as either JSON or YAML files containing the records you want to load. Each data file must specify records for a single table - if you need to load data into multiple tables, create separate data files for each table.
19+
20+
### Basic Example
21+
22+
Create a data file in your component's data directory (one table per file):
23+
24+
```json
25+
{
26+
"database": "myapp",
27+
"table": "users",
28+
"records": [
29+
{
30+
"id": 1,
31+
"username": "admin",
32+
"email": "[email protected]",
33+
"role": "administrator"
34+
},
35+
{
36+
"id": 2,
37+
"username": "user1",
38+
"email": "[email protected]",
39+
"role": "standard"
40+
}
41+
]
42+
}
43+
```
44+
45+
### Multiple Tables
46+
47+
To load data into multiple tables, create separate data files for each table:
48+
49+
**users.json:**
50+
```json
51+
{
52+
"database": "myapp",
53+
"table": "users",
54+
"records": [
55+
{
56+
"id": 1,
57+
"username": "admin",
58+
"email": "[email protected]"
59+
}
60+
]
61+
}
62+
```
63+
64+
**settings.yaml:**
65+
```yaml
66+
database: myapp
67+
table: settings
68+
records:
69+
- id: 1
70+
setting_name: app_name
71+
setting_value: My Application
72+
- id: 2
73+
setting_name: version
74+
setting_value: "1.0.0"
75+
```
76+
77+
## File Organization
78+
79+
You can organize your data files in various ways:
80+
81+
### Single File Pattern
82+
```yaml
83+
dataLoader:
84+
files: 'data/seed-data.json'
85+
```
86+
87+
### Multiple Files Pattern
88+
```yaml
89+
dataLoader:
90+
files:
91+
- 'data/users.json'
92+
- 'data/settings.yaml'
93+
- 'data/initial-products.json'
94+
```
95+
96+
### Glob Pattern
97+
```yaml
98+
dataLoader:
99+
files: 'data/**/*.{json,yaml,yml}'
100+
```
101+
102+
## Loading Behavior
103+
104+
When Harper starts up with a component that includes the Data Loader:
105+
106+
1. The Data Loader reads all specified data files (JSON or YAML)
107+
2. For each file, it validates that a single table is specified
108+
3. Records are inserted or updated based on timestamp comparison:
109+
- New records are inserted if they don't exist
110+
- Existing records are updated only if the data file's modification time is newer than the record's updated time
111+
- This ensures data files can be safely reloaded without overwriting newer changes
112+
4. If records with the same primary key already exist, updates occur only when the file is newer
113+
114+
Note: While the Data Loader can create tables automatically by inferring the schema from the provided records, it's recommended to define your table schemas explicitly using the [graphqlSchema](../applications/defining-schemas.md) component for better control and type safety.
115+
116+
## Best Practices
117+
118+
1. **Define Schemas First**: While the Data Loader can infer schemas, it's strongly recommended to define your table schemas and relations explicitly using the [graphqlSchema](../applications/defining-schemas.md) component before loading data. This ensures proper data types, constraints, and relationships between tables.
119+
120+
2. **One Table Per File**: Remember that each data file can only load records into a single table. Organize your files accordingly.
121+
122+
3. **Idempotency**: Design your data files to be idempotent - they should be safe to load multiple times without creating duplicate or conflicting data.
123+
124+
4. **Version Control**: Include your data files in version control to ensure consistency across deployments.
125+
126+
5. **Environment-Specific Data**: Consider using different data files for different environments (development, staging, production).
127+
128+
6. **Data Validation**: Ensure your data files are valid JSON or YAML and match your table schemas before deployment.
129+
130+
7. **Sensitive Data**: Avoid including sensitive data like passwords or API keys directly in data files. Use environment variables or secure configuration management instead.
131+
132+
## Example Component Structure
133+
134+
```
135+
my-component/
136+
├── config.yaml
137+
├── data/
138+
│ ├── users.json
139+
│ ├── roles.json
140+
│ └── settings.json
141+
├── schemas.graphql
142+
└── roles.yaml
143+
```
144+
145+
With this structure, your `config.yaml` might look like:
146+
147+
```yaml
148+
# Load environment variables first
149+
loadEnv:
150+
files: '.env'
151+
152+
# Define schemas
153+
graphqlSchema:
154+
files: 'schemas.graphql'
155+
156+
# Define roles
157+
roles:
158+
files: 'roles.yaml'
159+
160+
# Load initial data
161+
dataLoader:
162+
files: 'data/*.json'
163+
164+
# Enable REST endpoints
165+
rest: true
166+
```
167+
168+
## Related Documentation
169+
170+
- [Built-In Components](../components/built-in.md)
171+
- [Extensions](../components/reference.md#extensions)
172+
- [Bulk Operations](../operations-api/bulk-operations.md) - For loading data via the Operations API

docs/developers/operations-api/README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ Content-Type: application/json
1515

1616
The operations API reference is available below and categorized by topic:
1717

18-
- [Quick Start Examples](quickstart-examples.md)
19-
- [Databases and Tables](databases-and-tables.md)
20-
- [NoSQL Operations](nosql-operations.md)
21-
- [Bulk Operations](bulk-operations.md)
22-
- [Users and Roles](users-and-roles.md)
23-
- [Clustering](clustering.md)
24-
- [Clustering with NATS](clustering-nats.md)
25-
- [Components](components.md)
26-
- [Registration](registration.md)
27-
- [Jobs](jobs.md)
28-
- [Logs](logs.md)
29-
- [System Operations](system-operations.md)
30-
- [Configuration](configuration.md)
31-
- [Certificate Management](certificate-management.md)
32-
- [Token Authentication](token-authentication.md)
33-
- [SQL Operations](sql-operations.md)
34-
- [Advanced JSON SQL Examples](advanced-json-sql-examples.md)
18+
* [Quick Start Examples](quickstart-examples.md)
19+
* [Databases and Tables](databases-and-tables.md)
20+
* [NoSQL Operations](nosql-operations.md)
21+
* [Bulk Operations](bulk-operations.md)
22+
* [Users and Roles](users-and-roles.md)
23+
* [Clustering](clustering.md)
24+
* [Clustering with NATS](clustering-nats.md)
25+
* [Components](components.md)
26+
* [Registration](registration.md)
27+
* [Jobs](jobs.md)
28+
* [Logs](logs.md)
29+
* [System Operations](system-operations.md)
30+
* [Configuration](configuration.md)
31+
* [Certificate Management](certificate-management.md)
32+
* [Token Authentication](token-authentication.md)
33+
* [SQL Operations](sql-operations.md)
34+
* [Advanced JSON SQL Examples](advanced-json-sql-examples.md)
35+
* [Analytics](analytics.md)
3536

3637
[Past Release API Documentation](https://olddocs.harperdb.io)
3738

0 commit comments

Comments
 (0)