Skip to content
Merged
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: 2 additions & 1 deletion apps/backend/src/config/typeorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { registerAs } from '@nestjs/config';
import { PluralNamingStrategy } from '../strategies/plural-naming.strategy';
import { DataSource, DataSourceOptions } from 'typeorm';
import { User1725726359198 } from '../migrations/1725726359198-User';
import { AddTables1726524792261 } from '../migrations/1726524792261-addTables';

const config = {
type: 'postgres',
Expand All @@ -15,7 +16,7 @@ const config = {
namingStrategy: new PluralNamingStrategy(),
// Glob patterns (e.g. ../migrations/**.ts) are deprecated, so we have to manually specify each migration
// TODO: see if there's still a way to dynamically load all migrations
migrations: [User1725726359198],
migrations: [User1725726359198, AddTables1726524792261],
};

export default registerAs('typeorm', () => config);
Expand Down
39 changes: 39 additions & 0 deletions apps/backend/src/migrations/1726524792261-addTables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddTables1726524792261 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE IF NOT EXISTS pantries (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
approved BOOLEAN NOT NULL,
ssf_representative_id INT NOT NULL,
pantry_representative_id INT NOT NULL,
restrictions TEXT[] NOT NULL,

CONSTRAINT fk_ssf_representative_id FOREIGN KEY(ssf_representative_id) REFERENCES users(id),
CONSTRAINT fk_pantry_representative_id FOREIGN KEY(pantry_representative_id) REFERENCES users(id)
);

CREATE TABLE IF NOT EXISTS donations (
id SERIAL PRIMARY KEY,
restrictions TEXT[] NOT NULL,
due_date TIMESTAMP NOT NULL,
pantry_id INT NOT NULL,
status VARCHAR(50) NOT NULL,
feedback TEXT,
contents TEXT NOT NULL,

CONSTRAINT fk_pantry_id FOREIGN KEY(pantry_id) REFERENCES pantries(id)
);
`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP TABLE IF EXISTS pantries; DROP TABLE IF EXISTS donations;`,
);
}
}