Add resources table #184
Conversation
…udience, resource type
yellalena
left a comment
There was a problem hiding this comment.
thanks! great job with the built in constraints 🔥 left couple of comments
| } | ||
|
|
||
|
|
||
| Enum resource_audience { |
There was a problem hiding this comment.
yes, let's change it to audience, I think this value is generic enough to be possibly reused somewhere else
| audience resource_audience [not null] | ||
| description text | ||
| attachment_filename varchar(255) | ||
| link varchar(500) |
There was a problem hiding this comment.
do we actually need 500 characters for a link?
| exports.up = async function(knex) { | ||
| return knex.raw(` | ||
| ALTER TABLE tags_assigned | ||
| DROP CONSTRAINT IF EXISTS tags_assigned_assigned_to_check; |
There was a problem hiding this comment.
what is this constraint? when creating the table in 20251019074637_add_tags_tables.js we used inline enum definition. is this constraint automatically created in this case? 🤔
There was a problem hiding this comment.
yeah because as far as i understand when it comes to inline enum you have to actually to drop the constraint every time to recreate it in order to update it
| table.specificType('audience', 'resource_audience').notNullable(); | ||
| table.text('description'); | ||
| table.string('attachment_filename', 255); | ||
| table.string('link', 500); |
There was a problem hiding this comment.
same question, do we need 500 chars for a link?
There was a problem hiding this comment.
i'll leave it at 255 just in case
| * @returns { Promise<void> } | ||
| */ | ||
| exports.up = async function(knex) { | ||
| return knex.schema |
There was a problem hiding this comment.
please let's use async migrations with awaits inside
| exports.up = async function(knex) { | ||
| return knex.schema | ||
| // First create ENUM types if they don't exist | ||
| .raw(`CREATE TYPE resource_type AS ENUM ('post', 'video', 'picture', 'link', 'file');`) |
There was a problem hiding this comment.
will this omit creation if the type does not exist? in other migrations we did IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'mentor_status') THEN, I'm wondering if that was excessive or this one will fail if the type exists already
| table.text('description'); | ||
| table.string('attachment_filename', 255); | ||
| table.string('link', 500); | ||
| table.integer('created_by').unsigned().references('id').inTable('users'); |
There was a problem hiding this comment.
why do we need the .unsigned() here?
for feat #173
Added
resourcestable with checks and constraintsUpdated
tags_assignedtable to supportresourceconstraintAdded enums to Types:
resource_type,resource_audiencep.s. : if we ever use audience somewhere else, should i change to
audienceor leave it asresource_audience?