-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Multiple Gallery Store Images (#351)
* started migration * almost completed the query * change MerchandiseItemModel picture to pictures * renamed Merchandise to MercahndiseItems * generated a new model for the pictures * fixed syntax error with migration * understand and fix casting error * edited requests and created some todos * return position == 0 instead of first picture in array * migration temp fix * this one line of code would attach pictures to the collection so that the frontend can display the first picture * edited some todos to implement a new idea * edited the service * created a repository for photos * Completed the photo create route * completed the photo deletion route * getting started with seeding * make sure the index is consistent * removed the current file name from url for security purpose * quick linting * edited seeding to ensure correctness * update MerchFactory item for photo support * refactor and renaming variables * wrote outline for test and rewrote a method * fix error * edits * removing some junk code * the error is playing hide and seek with me * im such a genius * removing partial debug msgs * edits * fixed the order item test * finished creating tests and pass all tests * fixed some error * I CHATGPTED THE SQL AND IT WORKED * fixed linting error * edit migration number order * clean up some unused variables * renamed picture to uploadedPhoto and photo to merchPhoto for clarity, added some documentation * remove magic number * slight seeding edit * removed position logic * clarify cascading quetsion * fixed cascade * clean up * clarify seeding data structure * link fix * change position in request to string because form data does not accept number * throw error if position is not a number * updated deletion logic to delete from s3 first * link fix * default url logic fix for positions no longer being 0 * Test automated migrations–get another user's attendance (#379) * attendences from user uuid * lint and bugfix * check same user * controller factory changes * lint fixes * unit test for get attendance by uuid * lint * add permision * add types * add everything else * rename migrtion * test when permision is off * lint * forgor to add * change permission name and fix logic a bit * rename permission, change patch user * lint fix * lint fix * oops * check user exists * lint * new ci --------- Co-authored-by: Max Weng <[email protected]> * bumped my migration file number * bumped my migration file number v2 * remove local settings.json change * added edge case for migration up * lint * lint * such developer velocity * removed debugging --------- Co-authored-by: Nikhil Dange <[email protected]> Co-authored-by: Max Weng <[email protected]> Co-authored-by: Nikhil Dange <[email protected]>
- Loading branch information
1 parent
57f6c4a
commit f658e57
Showing
18 changed files
with
676 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { MigrationInterface, QueryRunner, Table, TableColumn } from 'typeorm'; | ||
|
||
const TABLE_NAME = 'MerchandiseItemPhotos'; | ||
const MERCH_TABLE_NAME = 'MerchandiseItems'; | ||
|
||
export class AddMerchItemImageTable1691286073347 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// instantiates table with columns: uuid, merchItem, uploadedPhoto, uploadedAt, position | ||
await queryRunner.createTable(new Table({ | ||
name: TABLE_NAME, | ||
columns: [ | ||
{ | ||
name: 'uuid', | ||
type: 'uuid', | ||
isGenerated: true, | ||
isPrimary: true, | ||
generationStrategy: 'uuid', | ||
}, | ||
{ | ||
name: 'merchItem', | ||
type: 'uuid', | ||
}, | ||
{ | ||
name: 'uploadedPhoto', | ||
type: 'varchar(255)', | ||
}, | ||
{ | ||
name: 'uploadedAt', | ||
type: 'timestamptz', | ||
default: 'CURRENT_TIMESTAMP(6)', | ||
}, | ||
{ | ||
name: 'position', | ||
type: 'integer', | ||
}, | ||
], | ||
// optimize searching | ||
indices: [ | ||
{ | ||
name: 'images_by_item_index', | ||
columnNames: ['merchItem'], | ||
}, | ||
], | ||
// cascade delete | ||
foreignKeys: [ | ||
{ | ||
columnNames: ['merchItem'], | ||
referencedTableName: MERCH_TABLE_NAME, | ||
referencedColumnNames: ['uuid'], | ||
onDelete: 'CASCADE', | ||
}, | ||
], | ||
})); | ||
|
||
// add images from each item of the merchandise table to the photo table | ||
await queryRunner.query( | ||
`INSERT INTO "${TABLE_NAME}" ("merchItem", "uploadedPhoto", position) ` | ||
+ `SELECT uuid, picture, 0 AS position FROM "${MERCH_TABLE_NAME}" ` | ||
+ 'WHERE picture IS NOT NULL', | ||
); | ||
|
||
// remove the column from the old table | ||
await queryRunner.dropColumn(`${MERCH_TABLE_NAME}`, 'picture'); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
// create old column (copied from migration #7) | ||
await queryRunner.addColumn(`${MERCH_TABLE_NAME}`, new TableColumn({ | ||
name: 'picture', | ||
type: 'varchar(255)', | ||
isNullable: true, | ||
})); | ||
|
||
// fill old column with the first image from the photo table | ||
await queryRunner.query( | ||
`UPDATE "${MERCH_TABLE_NAME}" m ` | ||
+ 'SET picture = (' | ||
+ 'SELECT "uploadedPhoto" ' | ||
+ `FROM "${TABLE_NAME}" p ` | ||
+ 'WHERE p."merchItem" = m.uuid ' | ||
+ 'ORDER BY p."uploadedAt" ' | ||
+ 'LIMIT 1' | ||
+ ')', | ||
); | ||
|
||
await queryRunner.dropTable(TABLE_NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { BaseEntity, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { PublicMerchItemPhoto, Uuid } from '../types'; | ||
import { MerchandiseItemModel } from './MerchandiseItemModel'; | ||
|
||
@Entity('MerchandiseItemPhotos') | ||
export class MerchandiseItemPhotoModel extends BaseEntity { | ||
@PrimaryGeneratedColumn('uuid') | ||
uuid: Uuid; | ||
|
||
@ManyToOne((type) => MerchandiseItemModel, | ||
(merchItem) => merchItem.merchPhotos, | ||
{ nullable: false, onDelete: 'CASCADE' }) | ||
@JoinColumn({ name: 'merchItem' }) | ||
@Index('images_by_item_index') | ||
merchItem: MerchandiseItemModel; | ||
|
||
@Column('varchar', { length: 255, nullable: false }) | ||
uploadedPhoto: string; | ||
|
||
@Column('timestamptz', { default: () => 'CURRENT_TIMESTAMP(6)', nullable: false }) | ||
uploadedAt: Date; | ||
|
||
@Column('integer') | ||
position: number; | ||
|
||
public getPublicMerchItemPhoto(): PublicMerchItemPhoto { | ||
return { | ||
uuid: this.uuid, | ||
uploadedPhoto: this.uploadedPhoto, | ||
uploadedAt: this.uploadedAt, | ||
position: this.position, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.