A database is an organized collection of data, generally stored and accessed electronically from a computer system. Where databases are more complex they are often developed using formal design and modeling techniques.
<aside> 📌 ❯ Query: normal DB queries ❯ Query Builder: write a query using JS, and it will be converted (Knex) ❯ ORM (Object Relational Map): write a query with instances (TypeORM) ❯ Migration: control the DB's versions and all the simultaneous changes
</aside>
Database migration is the process of migrating data from one or more source databases to one or more target databases by using a database migration service.
<aside> 👉 ❯ We can only change the migration code if this code is not versioned if the code is versioned, we must create another migration. ❯ On migration folder: up and down methods must have inversion behavior
</aside>
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'transactions',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'title',
type: 'varchar',
},
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('transactions');
}
<aside> 💡 • Consistency: A guarantee that each node in a distributed cluster returns the same most recent, successful write. Consistency refers to each customer having the same view of the data. • Availability: each request receives a response (no error) - no guarantee that it contains the most recent write. • Partition Tolerance: The system continues to work and the maintain your guarantees of consistency despite network partitions. Distributed systems that guarantee tolerance continue to operate, even if there is a failure in one of the nodes, since there is at least one node to perform the same work and guarantee the perfect functioning of the system.
</aside>
<aside> 💡 ACID (Atomicity, Consistency, Isolation, Durability)
</aside>