Bug 20568: (QA follow-up) Get rid of the id column
authorTomas Cohen Arazi <tomascohen@theke.io>
Sat, 14 Apr 2018 17:50:23 +0000 (14:50 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 9 May 2018 15:55:59 +0000 (12:55 -0300)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/Schema/Result/ApiKey.pm
installer/data/mysql/atomicupdate/bug_20568_api_keys.perl
installer/data/mysql/kohastructure.sql
members/apikeys.pl
opac/opac-apikeys.pl

index 3ff0570..f8e091f 100644 (file)
@@ -23,18 +23,6 @@ __PACKAGE__->table("api_keys");
 
 =head1 ACCESSORS
 
-=head2 id
-
-  data_type: 'integer'
-  is_auto_increment: 1
-  is_nullable: 0
-
-=head2 patron_id
-
-  data_type: 'integer'
-  is_foreign_key: 1
-  is_nullable: 0
-
 =head2 client_id
 
   data_type: 'varchar'
@@ -53,6 +41,12 @@ __PACKAGE__->table("api_keys");
   is_nullable: 0
   size: 255
 
+=head2 patron_id
+
+  data_type: 'integer'
+  is_foreign_key: 1
+  is_nullable: 0
+
 =head2 active
 
   data_type: 'tinyint'
@@ -62,16 +56,14 @@ __PACKAGE__->table("api_keys");
 =cut
 
 __PACKAGE__->add_columns(
-  "id",
-  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
-  "patron_id",
-  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
   "client_id",
   { data_type => "varchar", is_nullable => 0, size => 191 },
   "secret",
   { data_type => "varchar", is_nullable => 0, size => 191 },
   "description",
   { data_type => "varchar", is_nullable => 0, size => 255 },
+  "patron_id",
+  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
   "active",
   { data_type => "tinyint", default_value => 1, is_nullable => 0 },
 );
@@ -80,28 +72,16 @@ __PACKAGE__->add_columns(
 
 =over 4
 
-=item * L</id>
+=item * L</client_id>
 
 =back
 
 =cut
 
-__PACKAGE__->set_primary_key("id");
+__PACKAGE__->set_primary_key("client_id");
 
 =head1 UNIQUE CONSTRAINTS
 
-=head2 C<client_id>
-
-=over 4
-
-=item * L</client_id>
-
-=back
-
-=cut
-
-__PACKAGE__->add_unique_constraint("client_id", ["client_id"]);
-
 =head2 C<secret>
 
 =over 4
@@ -132,8 +112,8 @@ __PACKAGE__->belongs_to(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-04-14 00:56:23
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:b7AUAgl2SClXJ2lzPVV0FA
+# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-04-14 14:48:10
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qnu4QSACpOSQaZgd52ozmw
 
 __PACKAGE__->add_columns(
     '+active' => { is_boolean => 1 }
index 8cc0bf1..21e1884 100644 (file)
@@ -4,14 +4,12 @@ if(CheckVersion($DBversion)) {
     if (!TableExists('api_keys')) {
         $dbh->do(q{
             CREATE TABLE `api_keys` (
-                `id`          INT(11) NOT NULL AUTO_INCREMENT,
-                `patron_id`   INT(11) NOT NULL,
                 `client_id`   VARCHAR(191) NOT NULL,
                 `secret`      VARCHAR(191) NOT NULL,
                 `description` VARCHAR(255) NOT NULL,
+                `patron_id`   INT(11) NOT NULL,
                 `active`      TINYINT(1) DEFAULT 1 NOT NULL,
-                PRIMARY KEY (`id`),
-                UNIQUE KEY `client_id` (`client_id`),
+                PRIMARY KEY `client_id` (`client_id`),
                 UNIQUE KEY `secret` (`secret`),
                 KEY `patron_id` (`patron_id`),
                 CONSTRAINT `api_keys_fk_patron_id`
index 76d6dc2..f7970c0 100644 (file)
@@ -1719,16 +1719,14 @@ CREATE TABLE borrower_sync (
 
 DROP TABLE IF EXISTS `api_keys`;
 CREATE TABLE `api_keys` (
-    `id`          INT(11) NOT NULL AUTO_INCREMENT, -- API key internal identifier
-    `patron_id`   INT(11) NOT NULL,                -- Foreign key to the borrowers table
     `client_id`   VARCHAR(191) NOT NULL,           -- API client ID
     `secret`      VARCHAR(191) NOT NULL,           -- API client secret used for API authentication
     `description` VARCHAR(255) NOT NULL,           -- API client description
+    `patron_id`   INT(11) NOT NULL,                -- Foreign key to the borrowers table
     `active`      TINYINT(1) DEFAULT 1 NOT NULL,   -- 0 means this API key is revoked
-    PRIMARY KEY (`id`),
-    KEY `patron_id` (`patron_id`),
-    UNIQUE KEY `client_id` (`client_id`),
+    PRIMARY KEY `client_id` (`client_id`),
     UNIQUE KEY `secret` (`secret`),
+    KEY `patron_id` (`patron_id`),
     CONSTRAINT `api_keys_fk_patron_id`
       FOREIGN KEY (`patron_id`)
       REFERENCES `borrowers` (`borrowernumber`)
index 975ca86..fda98ed 100755 (executable)
@@ -68,7 +68,7 @@ if ($op) {
 
     if ( $op eq 'delete' ) {
         my $api_key_id = $cgi->param('key');
-        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
+        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $api_key_id });
         if ($key) {
             $key->delete;
         }
@@ -78,7 +78,7 @@ if ($op) {
 
     if ( $op eq 'revoke' ) {
         my $api_key_id = $cgi->param('key');
-        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
+        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $api_key_id });
         if ($key) {
             $key->active(0);
             $key->store;
@@ -89,7 +89,7 @@ if ($op) {
 
     if ( $op eq 'activate' ) {
         my $api_key_id = $cgi->param('key');
-        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
+        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $api_key_id });
         if ($key) {
             $key->active(1);
             $key->store;
index 66167e8..a571c16 100755 (executable)
@@ -63,7 +63,7 @@ if ($op) {
 
     if ($op eq 'delete') {
         my $key_id  = $cgi->param('key');
-        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
+        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $key_id });
         if ($api_key) {
             $api_key->delete;
         }
@@ -73,7 +73,7 @@ if ($op) {
 
     if ($op eq 'revoke') {
         my $key_id  = $cgi->param('key');
-        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
+        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $key_id });
         if ($api_key) {
             $api_key->active(0);
             $api_key->store;
@@ -84,7 +84,7 @@ if ($op) {
 
     if ($op eq 'activate') {
         my $key_id  = $cgi->param('key');
-        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
+        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $key_id });
         if ($api_key) {
             $api_key->active(1);
             $api_key->store;