1602 / 1602/jugglingdb

PostgreSQL, relationships - regular column created but there is no foreign key

Aperta
#430 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
2k
Fork
238
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Code example:

```
var schema = new Schema(driverType, connectionConfig);

var UserToken = schema.define('UserToken', {
token: {type: String, index: true}
}, {
tablename: 'user_token'
});

var User = schema.define('User', {
email: {type: String, allowNull: false, index: true},
password_hash: String,
first_name: String,
last_name: String,
role: {type: String, allowNull: false, default: 'member'},
language: {type: String, default: 'en'},
api_key: String,
active: {type: Boolean, allowNull: false, default: true},
confirmed: Date,
created: {type: Date, default: Date.now},
modified: Date
}, {
tablename: 'users'
});

User.hasMany(UserToken, {as: 'tokens', foreignKey: 'userId'});
UserToken.belongsTo(User, {as: 'user', foreignKey: 'userId'});

schema.automigrate();
```

Got DDLs:

```
CREATE TABLE public."UserToken" (
id serial NOT NULL DEFAULT nextval('"UserToken_id_seq"'::regclass),
token varchar,
"userId" int4,
CONSTRAINT "UserToken_pkey" PRIMARY KEY (id)
);
CREATE TABLE public."User" (
id serial NOT NULL DEFAULT nextval('"User_id_seq"'::regclass),
email varchar NOT NULL,
password_hash varchar,
first_name varchar,
last_name varchar,
role varchar NOT NULL,
"language" varchar,
api_key varchar,
active bool NOT NULL,
confirmed timestamptz,
created timestamptz,
modified timestamptz,
CONSTRAINT "User_pkey" PRIMARY KEY (id)
);
```

So "userId" column created as regular int4, but there is no foreignKey. The use of foreign keys is the basic concept of relational databases, it's required for data integrity.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Look at the schema definition and relationship mapping code in jugglingdb, likely in lib/schema.js or similar. The foreign key constraint is missing in PostgreSQL DDL generation. Check how automigrate works for PostgreSQL adapter, and see if foreign keys are being omitted. Test by creating a relationship and inspecting the generated SQL.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, postgresql
Ambito
backend, databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.