Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
tm-apps-db
Advanced tools
Apps backend database using the Sequalize library. See /models
and /migrations
.
index.js
: provides access to the DB using Sequalize APIssync.js
: command-line tool to init/synchronize the DB models.In order to view or generate an entity diagram of the database, go to ./db/docs/
and follow the instructions.
Read in MIGRATIONS.md
The following database credentials are created according to their use:
master
used for deployment pipelineconsumer
used by lambdas with read/write permissionsapi
used by APIs with read permissionsThe above credentials are injected in a migration file (sql\V001__add_roles.sql
) through prebuild.sh
script and is part of a migration step in the deployment pipeline using the Flyway tool.
This migration file is granting the right permissions on the database to the consumers
and apis
.
The credentials are stored in AWS Parameter Store in the format: /tm-apps-db/<DB_ROLE>/<username|password>
. Example: /tm-apps-db/api/username
.
There is a Chronos Seeding Job on Jenkins that is triggering the consumers based on DynamoDB data, but is not indicated to run on a large number of entries (more than 60k).
Go to Jenkins Chronos Reseeder job, fill in the the EscenicStateStore-<component>-<env>
, fill in the lambda name and run the job. This will query the specified table and run the consumer for each entry which in the end will write down to the PosgresDB.
Links:
Apps APIs are using database models for queries and hence this repo is delivered as an NPM package.
A new version can be deployed by updating the version number from package.json
file by following the semantic versioning syntax and tagging the commit with that version. When pushing the newly tag to git, a new package version will be published.
To bump up the package version, use npm version with --git-tag-version option - this will bump up the package version and it will automatically commit and tag the version change.
Eg:
npm version patch --git-tag-version
The above will increment the third digit of the version and it will tag the commit with that version.
Short description for semantic versioning syntax:
Stage | Rule | Example
----------------------------------------------------------------------------------
major | Increment the first digit and reset 2nd and 3rd digits to zero | 4.0.0
minor | Increment the middle digit and reset the 3rd digit to zero | 3.4.0
patch | Increment the 3rd digit | 3.4.2
To trigger the drone pipeline, run:
git push origin <tag>
Note that git push origin --tags
does not trigger the drone pipeline. It is however better to trigger it with only 1 tag referenced using git push origin <tag>
.
The database itself is deployed as a Cloudformation stack through Drone pipelines by promote
events to a specific environment:
drone build promote trinitymirror-ondemand/tm-apps-db 268 bertha
More information on promote
on the drone documentation.
Note: You may need to configure drone locally before being able to run this command (to get the DRONE_TOKEN
token, go to your drone's account):
export DRONE_SERVER=https://droneb.tm-dev-awx.com
export DRONE_TOKEN=<your_token_here>
drone info
There are 2 Cloudformation stacks that gets deployed:
tm-apps-db-env
containing a RDS instance (postgres), a security and a subnet group, with alarms set up for CPU and Storage spacetm-apps-db-dns-env
containing a Record Set for the RDS Instance addressThe drone step add-stack-policy
is adding a stack policy to the stack tm-apps-db-<env>
that block any deletion or replacement on RDS instances.
More information on AWS documentation.
The drone step add-stack-termination-protection
is adding a termination protection to the stack tm-apps-db-<env>
.
More information on AWS documentation.
If the database is created (or replaced during update), it can (or should) be based on a hardcoded DBSnapshotIdentifier
specified in the Drone file to properly support restore situations. A snapshot can be created via the AWS console (either from tm-apps-db-stable
for the dev
pipeline or tm-apps-db-prod
for the prod
pipeline). Then, replace the respective DBSnapshotIdentifier
field inside of the drone file. If the DB experienced some downtime during update, run the seeding job described further down in this file.
Note that once a DB instance is restored with a DBSnapshotIdentifier property, the same DBSnapshotIdentifier property must be specified for any future updates to the DB instance. This means that once the DB is created base on a snapshot, any further updates with the same snapshot identifier will not require a replacement of that DB.
Read more on AWS Guide about restoring a database from a snapshot using DBSnapshotIdentifier
.
sql\V001__add_roles.sql
or create a new migration file for granting the right permissions to consumers
and apis
which will run in the deployment pipeline with flyway
. If a new migration file is added, then consider to update the prebuild.sh
script accordingly.drone.yml
related to rule W3011
that require the UpdateReplacePolicy
field for an RDS instance. Adding this field would require a replacement of the DB which is not wanted at that time (as it is a risky operation); this field could be added when a time arrives when we need to delete or replace the RDS instance.DBSnapshotIdentifier
value in .drone.yml
fileTRIM_HORIZON
as their starting position, meaning that we can rely on the state store database streams to repopulate the missing data from the last 24hconsumers
and the apis
to point on the new database since they are pointing to the database DNS which gets updated with the new database address (default TTL is set to 60 seconds)add-stack-policy
, potentially by including stack policies into the trinitymirror/drone-cloudformation
image.is_live
field to article
table + created a migration filetag_id
column from tag
model. This was probably an error in the first place but was not damaging with previous versions of Sequelize. However, with v5, it nows breaks the code so it was needed to be taken outforeignKey
to each relevant associationupgrade sequelize from v3.24.3 to v5.21.5
model.find
alias was deprecated and replaced by model.findOne
classMethods
and instanceMethods
options from sequelize.define
and replaced by// Class Method
Model.associate = function (models) {
...associate the models
};
and
// Instance Method
Model.prototype.someMethod = function () {..}
upgrade commander from v2.20.0 to v5.0.0
upgrade pg from v6.1.0 to v7.18.2
upgrade sequelize-cli from v5.5.0 to v5.5.1
upgrade rambda from v to v0.27.0
add foreignKey
to relevant model associations
add define
property to configuration given new underscored
rule of sequelize v5, as:
config.define = {
createdAt: 'created_at',
updatedAt: 'updated_at',
deletedAt: 'deleted_at'
}
Note: version 4.0.0 to 4.0.5 are not working, first working version of v4 is v4.1.0
Last version (working) not tracked in this changelog.
FAQs
Apps consumer database initialiser
The npm package tm-apps-db receives a total of 14 weekly downloads. As such, tm-apps-db popularity was classified as not popular.
We found that tm-apps-db demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.