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

Add name property to Accounts #1900

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 4 additions & 0 deletions migrations/00006_account-names/index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE public.accounts
ADD COLUMN name bytea,
ADD COLUMN name_hash varchar(64),
ADD CONSTRAINT name_hash_unique UNIQUE (name_hash);
57 changes: 57 additions & 0 deletions migrations/__tests__/00006_account-names.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { TestDbFactory } from '@/__tests__/db.factory';
import { PostgresDatabaseMigrator } from '@/datasources/db/postgres-database.migrator';
import { faker } from '@faker-js/faker';
import postgres from 'postgres';

describe('Migration 00006_accounts-names', () => {
let sql: postgres.Sql;
let migrator: PostgresDatabaseMigrator;
const testDbFactory = new TestDbFactory();

beforeAll(async () => {
sql = await testDbFactory.createTestDatabase(faker.string.uuid());
migrator = new PostgresDatabaseMigrator(sql);
});

afterAll(async () => {
await testDbFactory.destroyTestDatabase(sql);
});

it('runs successfully', async () => {
const result = await migrator.test({
migration: '00006_account-names',
after: async (sql: postgres.Sql) => {
return {
accounts: {
columns:
await sql`SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'accounts'`,
rows: await sql`SELECT * FROM accounts`,
uniqueConstraints: await sql`
SELECT CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME = 'accounts' AND CONSTRAINT_TYPE = 'UNIQUE'`,
},
};
},
});

expect(result.after).toMatchObject({
accounts: {
columns: expect.arrayContaining([
{ column_name: 'id' },
{ column_name: 'group_id' },
{ column_name: 'address' },
{ column_name: 'name' },
{ column_name: 'name_hash' },
{ column_name: 'created_at' },
{ column_name: 'updated_at' },
]),
rows: [],
uniqueConstraints: expect.arrayContaining([
{ constraint_name: 'accounts_address_key' },
{ constraint_name: 'name_hash_unique' },
]),
},
});
});
});
Loading
Loading