|
| 1 | +exports.up = async (knex) => { |
| 2 | + await knex.schema.createTable('ossf_scorecard_results', (table) => { |
| 3 | + table.increments('id').primary() // Primary key |
| 4 | + table.float('analysis_score').notNullable() |
| 5 | + table.timestamp('analysis_time').notNullable() |
| 6 | + table.string('analysis_execution_time').notNullable() |
| 7 | + table.string('repo_commit').notNullable() |
| 8 | + table.string('scorecard_version').notNullable() |
| 9 | + table.string('scorecard_commit').notNullable() |
| 10 | + // binary_artifacts |
| 11 | + table.string('binary_artifacts_reason') |
| 12 | + table.float('binary_artifacts_score') |
| 13 | + table.string('binary_artifacts_documentation_url') |
| 14 | + table.string('binary_artifacts_documentation') |
| 15 | + table.text('binary_artifacts_details') |
| 16 | + // branch_protection |
| 17 | + table.string('branch_protection_reason') |
| 18 | + table.float('branch_protection_score') |
| 19 | + table.string('branch_protection_documentation_url') |
| 20 | + table.string('branch_protection_documentation') |
| 21 | + table.text('branch_protection_details') |
| 22 | + // ci_tests |
| 23 | + table.string('ci_tests_reason') |
| 24 | + table.float('ci_tests_score') |
| 25 | + table.string('ci_tests_documentation_url') |
| 26 | + table.string('ci_tests_documentation') |
| 27 | + table.text('ci_tests_details') |
| 28 | + // cii_best_practices |
| 29 | + table.string('cii_best_practices_reason') |
| 30 | + table.float('cii_best_practices_score') |
| 31 | + table.string('cii_best_practices_documentation_url') |
| 32 | + table.string('cii_best_practices_documentation') |
| 33 | + table.text('cii_best_practices_details') |
| 34 | + // code_review |
| 35 | + table.string('code_review_reason') |
| 36 | + table.float('code_review_score') |
| 37 | + table.string('code_review_documentation_url') |
| 38 | + table.string('code_review_documentation') |
| 39 | + table.text('code_review_details') |
| 40 | + // contributors |
| 41 | + table.string('contributors_reason') |
| 42 | + table.float('contributors_score') |
| 43 | + table.string('contributors_documentation_url') |
| 44 | + table.string('contributors_documentation') |
| 45 | + table.text('contributors_details') |
| 46 | + // dangerous_workflow |
| 47 | + table.string('dangerous_workflow_reason') |
| 48 | + table.float('dangerous_workflow_score') |
| 49 | + table.string('dangerous_workflow_documentation_url') |
| 50 | + table.string('dangerous_workflow_documentation') |
| 51 | + table.text('dangerous_workflow_details') |
| 52 | + // dependency_update_tool |
| 53 | + table.string('dependency_update_tool_reason') |
| 54 | + table.float('dependency_update_tool_score') |
| 55 | + table.string('dependency_update_tool_documentation_url') |
| 56 | + table.string('dependency_update_tool_documentation') |
| 57 | + table.text('dependency_update_tool_details') |
| 58 | + // fuzzing |
| 59 | + table.string('fuzzing_reason') |
| 60 | + table.float('fuzzing_score') |
| 61 | + table.string('fuzzing_documentation_url') |
| 62 | + table.string('fuzzing_documentation') |
| 63 | + table.text('fuzzing_details') |
| 64 | + // license |
| 65 | + table.string('license_reason') |
| 66 | + table.float('license_score') |
| 67 | + table.string('license_documentation_url') |
| 68 | + table.string('license_documentation') |
| 69 | + table.text('license_details') |
| 70 | + // maintained |
| 71 | + table.string('maintained_reason') |
| 72 | + table.float('maintained_score') |
| 73 | + table.string('maintained_documentation_url') |
| 74 | + table.string('maintained_documentation') |
| 75 | + table.text('maintained_details') |
| 76 | + // packaging |
| 77 | + table.string('packaging_reason') |
| 78 | + table.float('packaging_score') |
| 79 | + table.string('packaging_documentation_url') |
| 80 | + table.string('packaging_documentation') |
| 81 | + table.text('packaging_details') |
| 82 | + // pinned_dependencies |
| 83 | + table.string('pinned_dependencies_reason') |
| 84 | + table.float('pinned_dependencies_score') |
| 85 | + table.string('pinned_dependencies_documentation_url') |
| 86 | + table.string('pinned_dependencies_documentation') |
| 87 | + table.text('pinned_dependencies_details') |
| 88 | + // sast |
| 89 | + table.string('sast_reason') |
| 90 | + table.float('sast_score') |
| 91 | + table.string('sast_documentation_url') |
| 92 | + table.string('sast_documentation') |
| 93 | + table.text('sast_details') |
| 94 | + // security_policy |
| 95 | + table.string('security_policy_reason') |
| 96 | + table.float('security_policy_score') |
| 97 | + table.string('security_policy_documentation_url') |
| 98 | + table.string('security_policy_documentation') |
| 99 | + table.text('security_policy_details') |
| 100 | + // signed_releases |
| 101 | + table.string('signed_releases_reason') |
| 102 | + table.float('signed_releases_score') |
| 103 | + table.string('signed_releases_documentation_url') |
| 104 | + table.string('signed_releases_documentation') |
| 105 | + table.text('signed_releases_details') |
| 106 | + // token_permissions |
| 107 | + table.string('token_permissions_reason') |
| 108 | + table.float('token_permissions_score') |
| 109 | + table.string('token_permissions_documentation_url') |
| 110 | + table.string('token_permissions_documentation') |
| 111 | + table.text('token_permissions_details') |
| 112 | + // vulnerabilities |
| 113 | + table.string('vulnerabilities_reason') |
| 114 | + table.float('vulnerabilities_score') |
| 115 | + table.string('vulnerabilities_documentation_url') |
| 116 | + table.string('vulnerabilities_documentation') |
| 117 | + table.text('vulnerabilities_details') |
| 118 | + |
| 119 | + // Foreign key to 'projects' table |
| 120 | + table |
| 121 | + .integer('github_repository_id') |
| 122 | + .unsigned() |
| 123 | + .references('id') |
| 124 | + .inTable('github_repositories') |
| 125 | + .onDelete('CASCADE') // Deletes repository if the organization is deleted |
| 126 | + .onUpdate('CASCADE') // Updates repository if the organization ID is updated |
| 127 | + .notNullable() |
| 128 | + |
| 129 | + // Timestamps |
| 130 | + table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable() |
| 131 | + table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable() |
| 132 | + }) |
| 133 | + |
| 134 | + // Add trigger to automatically update the 'updated_at' column |
| 135 | + await knex.raw(` |
| 136 | + CREATE TRIGGER set_updated_at_ossf_scorecard_results |
| 137 | + BEFORE UPDATE ON ossf_scorecard_results |
| 138 | + FOR EACH ROW |
| 139 | + EXECUTE FUNCTION update_updated_at_column(); |
| 140 | + `) |
| 141 | +} |
| 142 | + |
| 143 | +exports.down = async (knex) => { |
| 144 | + // Drop trigger |
| 145 | + await knex.raw('DROP TRIGGER IF EXISTS set_updated_at_ossf_scorecard_results ON ossf_scorecard_results;') |
| 146 | + // Drop table |
| 147 | + await knex.schema.dropTableIfExists('ossf_scorecard_results') |
| 148 | +} |
0 commit comments