Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added data rotation function #15

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules/
.idea/
.vscode/
*.log
audits
.env.**
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,78 @@ await myModel
.delete()
```

# Rotation

## Register provider

Once you have installed adonis-audit, make sure to register the provider inside `start/app.js` in order to make use of it.

```js
const providers = ['@ks-labs/adonis-audit/providers/AuditRotationProvider']
```

## Register Command

Register the command inside `start/app/js`

```js
const command = ['@ks-labs/adonis-audit/src/Command/AuditCommand']
```

Initialize audit command

```js
adonis make:auditRotation
```

The above command will create the rotation audit configuration file

`config/audit.js`

```js
'use strict'

const Env = use('Env')

module.exports = {
// redis connection
enabled: Env.get('ENABLED_AUDIT_ROTATION', true),
retention: Env.get('RETENTION_AUDIT_ROTATION', '3'),
pruneDatabase: Env.get('PRUNE_DATABASE_AUDIT_ROTATION', true),
deleteFileAfterUpload: Env.get('DELETE_FILE_AFTER_UPLOAD_AUDIT_ROTATION', true),

logger: {
'level': 'debug',
'transport': 'pino-pretty',
'pino-pretty': {
level: 'info',
target: 'pino-pretty',
},
},
}
```

### _It is highly important to add an index to the `created_at` column of the audit table to improve performance in queries performed by data rotation_

## Use

You can use the lib's scheduling service `schedule()` or create your own rotation strategy using the `run()` command.

```js
/** @type { import('../src/Rotation/index')} */
const DataRotation = ioc.use('Adonis/Addons/DataRotation')

// Run rotation
await DataRotation.run()

// Run scheduling
await DataRotation.schedule('* * * * * ')
```

## Diagram

![Alt text](d__Documents_3C_adonis-audit_retention.svg)

## Built For

- [Legacy AdonisJS 4.1](http://legacy.adonisjs.com) - The web framework used.
Expand Down
2 changes: 1 addition & 1 deletion bin/dev.japaFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { configure } = require('japa')

configure({
files: ['test/*.test.js', 'test/*.spec.js'],
files: ['test/*.test.js', 'test/*.spec.js'],,

timeout: 30000,
})
17 changes: 17 additions & 0 deletions d__Documents_3C_adonis-audit_retention.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading