|
| 1 | +exports.up = async (knex) => { |
| 2 | + // Create 'github_repositories' table |
| 3 | + await knex.schema.createTable('github_repositories', (table) => { |
| 4 | + table.increments('id').primary() // Primary key |
| 5 | + table.string('node_id').unique().notNullable() |
| 6 | + table.string('name').notNullable() |
| 7 | + table.string('full_name').notNullable() |
| 8 | + table.string('html_url').notNullable() |
| 9 | + table.text('description') |
| 10 | + table.boolean('fork') |
| 11 | + table.string('url').notNullable() |
| 12 | + table.string('git_url').notNullable() |
| 13 | + table.string('ssh_url').notNullable() |
| 14 | + table.string('clone_url').notNullable() |
| 15 | + table.string('svn_url') |
| 16 | + table.string('homepage') |
| 17 | + table.integer('size') |
| 18 | + table.integer('stargazers_count') |
| 19 | + table.integer('watchers_count') |
| 20 | + table.string('language') |
| 21 | + table.boolean('has_issues') |
| 22 | + table.boolean('has_projects') |
| 23 | + table.boolean('has_downloads') |
| 24 | + table.boolean('has_wiki') |
| 25 | + table.boolean('has_pages') |
| 26 | + table.boolean('has_discussions') |
| 27 | + table.integer('forks_count') |
| 28 | + table.string('mirror_url') |
| 29 | + table.boolean('archived') |
| 30 | + table.boolean('disabled') |
| 31 | + table.integer('open_issues_count') |
| 32 | + table.boolean('allow_forking') |
| 33 | + table.boolean('is_template') |
| 34 | + table.boolean('web_commit_signoff_required') |
| 35 | + table.specificType('topics', 'text[]') // Array of strings |
| 36 | + table.enu('visibility', ['public', 'private', 'internal']).notNullable() |
| 37 | + table.string('default_branch').notNullable() |
| 38 | + table.boolean('allow_squash_merge') |
| 39 | + table.boolean('allow_merge_commit') |
| 40 | + table.boolean('allow_rebase_merge') |
| 41 | + table.boolean('allow_auto_merge') |
| 42 | + table.boolean('delete_branch_on_merge') |
| 43 | + table.boolean('allow_update_branch') |
| 44 | + table.boolean('use_squash_pr_title_as_default') |
| 45 | + table.string('squash_merge_commit_message') |
| 46 | + table.string('squash_merge_commit_title') |
| 47 | + table.string('merge_commit_message') |
| 48 | + table.string('merge_commit_title') |
| 49 | + table.integer('network_count') |
| 50 | + table.integer('subscribers_count') |
| 51 | + table.integer('github_repo_id').unique() |
| 52 | + table.timestamp('github_created_at') |
| 53 | + table.timestamp('github_updated_at') |
| 54 | + table.timestamp('github_archived_at') |
| 55 | + table.string('license_key') |
| 56 | + table.string('license_name') |
| 57 | + table.string('license_spdx_id') |
| 58 | + table.string('license_url') |
| 59 | + table.string('license_node_id') |
| 60 | + table.enu('secret_scanning_status', ['enabled', 'disabled']).defaultTo('disabled') |
| 61 | + table.enu('secret_scanning_push_protection_status', ['enabled', 'disabled']).defaultTo('disabled') |
| 62 | + table.enu('dependabot_security_updates_status', ['enabled', 'disabled']).defaultTo('disabled') |
| 63 | + table.enu('secret_scanning_non_provider_patterns_status', ['enabled', 'disabled']).defaultTo('disabled') |
| 64 | + table.enu('secret_scanning_validity_checks_status', ['enabled', 'disabled']).defaultTo('disabled') |
| 65 | + |
| 66 | + // Foreign key to 'github_organizations' table |
| 67 | + table |
| 68 | + .integer('github_organization_id') |
| 69 | + .unsigned() |
| 70 | + .references('id') |
| 71 | + .inTable('github_organizations') |
| 72 | + .onDelete('CASCADE') // Deletes repository if the organization is deleted |
| 73 | + .onUpdate('CASCADE') // Updates repository if the organization ID is updated |
| 74 | + |
| 75 | + // Timestamps |
| 76 | + table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable() |
| 77 | + table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable() |
| 78 | + }) |
| 79 | + |
| 80 | + // Add trigger to 'github_repositories' table |
| 81 | + await knex.raw(` |
| 82 | + CREATE TRIGGER set_updated_at_github_repositories |
| 83 | + BEFORE UPDATE ON github_repositories |
| 84 | + FOR EACH ROW |
| 85 | + EXECUTE FUNCTION update_updated_at_column(); |
| 86 | + `) |
| 87 | +} |
| 88 | + |
| 89 | +exports.down = async (knex) => { |
| 90 | + // Drop trigger |
| 91 | + await knex.raw('DROP TRIGGER IF EXISTS set_updated_at_github_repositories ON github_repositories;') |
| 92 | + // Drop table |
| 93 | + await knex.schema.dropTableIfExists('github_repositories') |
| 94 | +} |
0 commit comments