@@ -6,7 +6,7 @@ import { hasMigrationBeenCreated } from '../index'
6
6
export function getTraitTables ( ) : string [ ] {
7
7
return [
8
8
'tags' ,
9
- 'taggable_models ' ,
9
+ 'taggables ' ,
10
10
'categorizables' ,
11
11
'comments' ,
12
12
'commentables' ,
@@ -87,7 +87,7 @@ export async function createPostgresPasskeyMigration(): Promise<void> {
87
87
}
88
88
89
89
export async function createTaggableTable ( ) : Promise < void > {
90
- const hasBeenMigrated = await hasMigrationBeenCreated ( 'taggable ' )
90
+ const hasBeenMigrated = await hasMigrationBeenCreated ( 'tags ' )
91
91
92
92
if ( hasBeenMigrated )
93
93
return
@@ -109,19 +109,19 @@ export async function createTaggableTable(): Promise<void> {
109
109
migrationContent += ` .execute()\n\n`
110
110
111
111
migrationContent += ` await db.schema\n`
112
- migrationContent += ` .createIndex('idx_tag_slug ')\n`
112
+ migrationContent += ` .createIndex('idx_tags_slug ')\n`
113
113
migrationContent += ` .on('tags')\n`
114
114
migrationContent += ` .column('slug')\n`
115
115
migrationContent += ` .execute()\n\n`
116
116
117
117
migrationContent += ` await db.schema\n`
118
- migrationContent += ` .createIndex('idx_tag_type ')\n`
118
+ migrationContent += ` .createIndex('idx_tags_type ')\n`
119
119
migrationContent += ` .on('tags')\n`
120
120
migrationContent += ` .column('type')\n`
121
121
migrationContent += ` .execute()\n\n`
122
122
123
123
migrationContent += ` await db.schema\n`
124
- migrationContent += ` .createIndex('idx_tag_name ')\n`
124
+ migrationContent += ` .createIndex('idx_tags_name ')\n`
125
125
migrationContent += ` .on('tags')\n`
126
126
migrationContent += ` .column('name')\n`
127
127
migrationContent += ` .execute()\n\n`
@@ -136,11 +136,11 @@ export async function createTaggableTable(): Promise<void> {
136
136
137
137
log . success ( `Created migration: ${ italic ( migrationFileName ) } ` )
138
138
139
- await createTaggableModelsTable ( )
139
+ await createTaggablesTable ( )
140
140
}
141
141
142
142
export async function createPostgresTaggableTable ( ) : Promise < void > {
143
- const hasBeenMigrated = await hasMigrationBeenCreated ( 'taggable ' )
143
+ const hasBeenMigrated = await hasMigrationBeenCreated ( 'tags ' )
144
144
145
145
if ( hasBeenMigrated )
146
146
return
@@ -188,6 +188,8 @@ export async function createPostgresTaggableTable(): Promise<void> {
188
188
Bun . write ( migrationFilePath , migrationContent )
189
189
190
190
log . success ( `Created migration: ${ italic ( migrationFileName ) } ` )
191
+
192
+ await createPostgresTaggablesTable ( )
191
193
}
192
194
193
195
// SQLite/MySQL version
@@ -399,7 +401,7 @@ export async function dropCommonTables(): Promise<void> {
399
401
await db . schema . dropTable ( 'categorizables' ) . ifExists ( ) . execute ( )
400
402
await db . schema . dropTable ( 'commenteable_upvotes' ) . ifExists ( ) . execute ( )
401
403
await db . schema . dropTable ( 'tags' ) . ifExists ( ) . execute ( )
402
- await db . schema . dropTable ( 'taggable_models ' ) . ifExists ( ) . execute ( )
404
+ await db . schema . dropTable ( 'taggables ' ) . ifExists ( ) . execute ( )
403
405
await db . schema . dropTable ( 'categorizable_models' ) . ifExists ( ) . execute ( )
404
406
await db . schema . dropTable ( 'commentables' ) . ifExists ( ) . execute ( )
405
407
await db . schema . dropTable ( 'comments' ) . ifExists ( ) . execute ( )
@@ -576,8 +578,8 @@ export async function createPostgresCommentablesPivotTable(): Promise<void> {
576
578
log . success ( `Created migration: ${ italic ( migrationFileName ) } ` )
577
579
}
578
580
579
- export async function createTaggableModelsTable ( ) : Promise < void > {
580
- const hasBeenMigrated = await hasMigrationBeenCreated ( 'taggable_models ' )
581
+ export async function createTaggablesTable ( ) : Promise < void > {
582
+ const hasBeenMigrated = await hasMigrationBeenCreated ( 'taggables ' )
581
583
582
584
if ( hasBeenMigrated )
583
585
return
@@ -586,7 +588,7 @@ export async function createTaggableModelsTable(): Promise<void> {
586
588
migrationContent += `import { sql } from '@stacksjs/database'\n\n`
587
589
migrationContent += `export async function up(db: Database<any>) {\n`
588
590
migrationContent += ` await db.schema\n`
589
- migrationContent += ` .createTable('taggable_models ')\n`
591
+ migrationContent += ` .createTable('taggables ')\n`
590
592
migrationContent += ` .addColumn('id', 'integer', col => col.primaryKey().autoIncrement())\n`
591
593
migrationContent += ` .addColumn('tag_id', 'integer', col => col.notNull())\n`
592
594
migrationContent += ` .addColumn('taggable_id', 'integer', col => col.notNull())\n`
@@ -597,42 +599,42 @@ export async function createTaggableModelsTable(): Promise<void> {
597
599
598
600
// Add foreign key constraint to tags table
599
601
migrationContent += ` await db.schema\n`
600
- migrationContent += ` .alterTable('taggable_models ')\n`
601
- migrationContent += ` .addForeignKeyConstraint('taggable_models_tag_id_foreign ', ['tag_id'], 'tags', ['id'], (cb) => cb.onDelete('cascade'))\n`
602
+ migrationContent += ` .alterTable('taggables ')\n`
603
+ migrationContent += ` .addForeignKeyConstraint('taggables_tag_id_foreign ', ['tag_id'], 'tags', ['id'], (cb) => cb.onDelete('cascade'))\n`
602
604
migrationContent += ` .execute()\n\n`
603
605
604
606
migrationContent += ` await db.schema\n`
605
- migrationContent += ` .createIndex('idx_taggable_models_tag ')\n`
606
- migrationContent += ` .on('taggable_models ')\n`
607
+ migrationContent += ` .createIndex('idx_taggables_tag ')\n`
608
+ migrationContent += ` .on('taggables ')\n`
607
609
migrationContent += ` .column('tag_id')\n`
608
610
migrationContent += ` .execute()\n\n`
609
611
610
612
migrationContent += ` await db.schema\n`
611
- migrationContent += ` .createIndex('idx_taggable_models_polymorphic ')\n`
612
- migrationContent += ` .on('taggable_models ')\n`
613
+ migrationContent += ` .createIndex('idx_taggables_polymorphic ')\n`
614
+ migrationContent += ` .on('taggables ')\n`
613
615
migrationContent += ` .columns(['taggable_id', 'taggable_type'])\n`
614
616
migrationContent += ` .execute()\n\n`
615
617
616
618
migrationContent += ` await db.schema\n`
617
- migrationContent += ` .createIndex('idx_taggable_models_unique ')\n`
618
- migrationContent += ` .on('taggable_models ')\n`
619
+ migrationContent += ` .createIndex('idx_taggables_unique ')\n`
620
+ migrationContent += ` .on('taggables ')\n`
619
621
migrationContent += ` .columns(['tag_id', 'taggable_id', 'taggable_type'])\n`
620
622
migrationContent += ` .unique()\n`
621
623
migrationContent += ` .execute()\n\n`
622
624
623
625
migrationContent += `}\n`
624
626
625
627
const timestamp = new Date ( ) . getTime ( ) . toString ( )
626
- const migrationFileName = `${ timestamp } -create-taggable-models -table.ts`
628
+ const migrationFileName = `${ timestamp } -create-taggables -table.ts`
627
629
const migrationFilePath = path . userMigrationsPath ( migrationFileName )
628
630
629
631
Bun . write ( migrationFilePath , migrationContent )
630
632
631
633
log . success ( `Created migration: ${ italic ( migrationFileName ) } ` )
632
634
}
633
635
634
- export async function createPostgresTaggableModelsTable ( ) : Promise < void > {
635
- const hasBeenMigrated = await hasMigrationBeenCreated ( 'taggable_models ' )
636
+ export async function createPostgresTaggablesTable ( ) : Promise < void > {
637
+ const hasBeenMigrated = await hasMigrationBeenCreated ( 'taggables ' )
636
638
637
639
if ( hasBeenMigrated )
638
640
return
@@ -641,7 +643,7 @@ export async function createPostgresTaggableModelsTable(): Promise<void> {
641
643
migrationContent += `import { sql } from '@stacksjs/database'\n\n`
642
644
migrationContent += `export async function up(db: Database<any>) {\n`
643
645
migrationContent += ` await db.schema\n`
644
- migrationContent += ` .createTable('taggable_models ')\n`
646
+ migrationContent += ` .createTable('taggables ')\n`
645
647
migrationContent += ` .addColumn('id', 'serial', col => col.primaryKey())\n`
646
648
migrationContent += ` .addColumn('tag_id', 'integer', col => col.notNull())\n`
647
649
migrationContent += ` .addColumn('taggable_id', 'integer', col => col.notNull())\n`
@@ -652,33 +654,33 @@ export async function createPostgresTaggableModelsTable(): Promise<void> {
652
654
653
655
// Add foreign key constraint to tags table
654
656
migrationContent += ` await db.schema\n`
655
- migrationContent += ` .alterTable('taggable_models ')\n`
656
- migrationContent += ` .addForeignKeyConstraint('taggable_models_tag_id_foreign ', ['tag_id'], 'tags', ['id'], (cb) => cb.onDelete('cascade'))\n`
657
+ migrationContent += ` .alterTable('taggables ')\n`
658
+ migrationContent += ` .addForeignKeyConstraint('taggables_tag_id_foreign ', ['tag_id'], 'tags', ['id'], (cb) => cb.onDelete('cascade'))\n`
657
659
migrationContent += ` .execute()\n\n`
658
660
659
661
migrationContent += ` await db.schema\n`
660
- migrationContent += ` .createIndex('idx_taggable_models_tag ')\n`
661
- migrationContent += ` .on('taggable_models ')\n`
662
+ migrationContent += ` .createIndex('idx_taggables_tag ')\n`
663
+ migrationContent += ` .on('taggables ')\n`
662
664
migrationContent += ` .column('tag_id')\n`
663
665
migrationContent += ` .execute()\n\n`
664
666
665
667
migrationContent += ` await db.schema\n`
666
- migrationContent += ` .createIndex('idx_taggable_models_polymorphic ')\n`
667
- migrationContent += ` .on('taggable_models ')\n`
668
+ migrationContent += ` .createIndex('idx_taggables_polymorphic ')\n`
669
+ migrationContent += ` .on('taggables ')\n`
668
670
migrationContent += ` .columns(['taggable_id', 'taggable_type'])\n`
669
671
migrationContent += ` .execute()\n\n`
670
672
671
673
migrationContent += ` await db.schema\n`
672
- migrationContent += ` .createIndex('idx_taggable_models_unique ')\n`
673
- migrationContent += ` .on('taggable_models ')\n`
674
+ migrationContent += ` .createIndex('idx_taggables_unique ')\n`
675
+ migrationContent += ` .on('taggables ')\n`
674
676
migrationContent += ` .columns(['tag_id', 'taggable_id', 'taggable_type'])\n`
675
677
migrationContent += ` .unique()\n`
676
678
migrationContent += ` .execute()\n\n`
677
679
678
680
migrationContent += `}\n`
679
681
680
682
const timestamp = new Date ( ) . getTime ( ) . toString ( )
681
- const migrationFileName = `${ timestamp } -create-taggable-models -table.ts`
683
+ const migrationFileName = `${ timestamp } -create-taggables -table.ts`
682
684
const migrationFilePath = path . userMigrationsPath ( migrationFileName )
683
685
684
686
Bun . write ( migrationFilePath , migrationContent )
0 commit comments