{"size": 3559, "ext": "js", "max_stars_repo_path": "src/migrations/20181204161731_OAuth.js", "max_stars_repo_name": "edevil/node-webapp-sample-js", "max_stars_repo_stars_event_min_datetime": "2019-04-29T10:23:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-29T10:23:10.000Z", "max_issues_repo_path": "src/migrations/20181204161731_OAuth.js", "max_issues_repo_name": "edevil/node-webapp-sample-js", "max_issues_repo_issues_event_min_datetime": "2019-06-17T13:35:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T04:30:15.000Z", "max_forks_repo_path": "src/migrations/20181204161731_OAuth.js", "max_forks_repo_name": "edevil/node-webapp-sample-js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 122, "max_forks_count": null, "avg_line_length": 27.5891472868, "max_line_length": 69, "alphanum_fraction": 0.5636414723}
exports.up = (knex) => {
  return Promise.all([
    knex.schema.createTable("o_auth_client", table => {
      table
        .uuid("id")
        .primary()
        .defaultTo(knex.raw("uuid_generate_v4()"));
      table.string("secret").notNullable();
      table.specificType("redirectUris", "text array").notNullable();
      table.specificType("grants", "text array").notNullable();
      table.specificType("scopes", "text array").notNullable();
      table.integer("userId").notNullable();
      table
        .foreign("userId")
        .references("id")
        .inTable("user")
        .onDelete("cascade");
      table
        .timestamp("createdAt")
        .defaultTo(knex.fn.now())
        .notNullable();
      table
        .timestamp("updatedAt")
        .defaultTo(knex.fn.now())
        .notNullable();
    }),
    knex.schema.createTable("o_auth_refresh_token", table => {
      table
        .string("refreshToken")
        .notNullable()
        .primary();
      table.text("scope").notNullable();
      table.timestamp("refreshTokenExpiresAt").notNullable();

      table.integer("userId").notNullable();
      table
        .foreign("userId")
        .references("id")
        .inTable("user")
        .onDelete("cascade");

      table.uuid("clientId").notNullable();
      table
        .foreign("clientId")
        .references("id")
        .inTable("o_auth_client")
        .onDelete("cascade");
      table
        .timestamp("createdAt")
        .defaultTo(knex.fn.now())
        .notNullable();
      table
        .timestamp("updatedAt")
        .defaultTo(knex.fn.now())
        .notNullable();
    }),
    knex.schema.createTable("o_auth_authorization_code", table => {
      table
        .string("authorizationCode")
        .notNullable()
        .primary();
      table.timestamp("expiresAt").notNullable();
      table.text("redirectUri").notNullable();
      table.text("scope").notNullable();
      table
        .timestamp("createdAt")
        .defaultTo(knex.fn.now())
        .notNullable();
      table
        .timestamp("updatedAt")
        .defaultTo(knex.fn.now())
        .notNullable();

      table.integer("userId").notNullable();
      table
        .foreign("userId")
        .references("id")
        .inTable("user")
        .onDelete("cascade");

      table.uuid("clientId").notNullable();
      table
        .foreign("clientId")
        .references("id")
        .inTable("o_auth_client")
        .onDelete("cascade");
    }),
    knex.schema.createTable("o_auth_access_token", table => {
      table
        .string("accessToken")
        .notNullable()
        .primary();
      table.text("scope").notNullable();
      table.timestamp("accessTokenExpiresAt").notNullable();
      table
        .timestamp("createdAt")
        .defaultTo(knex.fn.now())
        .notNullable();
      table
        .timestamp("updatedAt")
        .defaultTo(knex.fn.now())
        .notNullable();

      table.integer("userId").notNullable();
      table
        .foreign("userId")
        .references("id")
        .inTable("user")
        .onDelete("cascade");

      table.uuid("clientId").notNullable();
      table
        .foreign("clientId")
        .references("id")
        .inTable("o_auth_client")
        .onDelete("cascade");
    }),
  ]);
};

exports.down = (knex) => {
  return Promise.all([
    knex.schema.dropTable("o_auth_access_token"),
    knex.schema.dropTable("o_auth_authorization_code"),
    knex.schema.dropTable("o_auth_refresh_token"),
    knex.schema.dropTable("o_auth_client"),
  ]);
};
