{"id":23441619,"url":"https://github.com/chalonov/db-university-postgresql","last_synced_at":"2026-02-16T17:04:57.673Z","repository":{"id":269449181,"uuid":"902663589","full_name":"chalonov/db-university-postgresql","owner":"chalonov","description":"University Distributed Database System for managing academic and library operations across multiple faculties.","archived":false,"fork":false,"pushed_at":"2024-12-17T16:07:53.000Z","size":281,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T13:37:32.709Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chalonov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-13T02:43:47.000Z","updated_at":"2024-12-17T16:07:56.000Z","dependencies_parsed_at":"2024-12-23T17:27:47.239Z","dependency_job_id":null,"html_url":"https://github.com/chalonov/db-university-postgresql","commit_stats":null,"previous_names":["chalonov/db-university-postgresql"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalonov%2Fdb-university-postgresql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalonov%2Fdb-university-postgresql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalonov%2Fdb-university-postgresql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalonov%2Fdb-university-postgresql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chalonov","download_url":"https://codeload.github.com/chalonov/db-university-postgresql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248113772,"owners_count":21049901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["architecture","database","dblink","entity-relationship-diagram","library-database","postgresql"],"created_at":"2024-12-23T17:17:35.337Z","updated_at":"2025-09-24T17:21:26.797Z","avatar_url":"https://github.com/chalonov.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# University Distributed Database System\nVersion 1.0.0\n\n## Table of Contents\n1. [System Overview](#system-overview)\n2. [Architecture](#architecture)\n3. [Database Schemas](#database-schemas)\n4. [Security Model](#security-model)\n5. [Business Rules](#business-rules)\n6. [Integration Points](#integration-points)\n7. [Operational Procedures](#operational-procedures)\n8. [Development Guidelines](#development-guidelines)\n9. [Maintenance and Support](#maintenance-and-support)\n\n![Distributed database system architecture](./diagrams/distributed_database_systems.png)\n\n## System Overview\n\nThe University Distributed Database System implements a comprehensive solution for managing academic and library operations across multiple faculties. The system utilizes PostgreSQL's distributed capabilities to create an integrated network of databases that share information while maintaining data integrity and security.\n\n### Purpose\n\nThe system serves three primary objectives:\n1. Managing academic operations including student enrollment, course administration, and grade tracking\n2. Supporting library operations with book inventory and lending management\n3. Facilitating cross-faculty resource sharing and academic coordination\n\n### Scope\n\nThe system encompasses:\n- Central library database with book management and lending operations\n- Individual faculty databases managing academic programs\n- Cross-database communication infrastructure\n- Role-based access control system\n- Automated user management\n\n## Architecture\n\n### Distributed System Design\n\nThe system implements a hub-and-spoke architecture where:\n- The central library database serves as the hub\n- Faculty databases operate as independent nodes\n- Database links (dblink) facilitate inter-database communication\n- Each node maintains its own security and user management\n\n### Network Infrastructure\n\nThe implementation requires:\n- High-availability database servers\n- Secure network connections between nodes\n- Load balancing for distributed queries\n- Backup and recovery infrastructure\n\n## Database Schemas\n\n### Library Schema (biblioteca)\n\n#### Domain Definitions\n```sql\nCREATE DOMAIN CODE_DOMAIN varchar(20) NOT NULL;\nCREATE DOMAIN ID_DOMAIN integer NOT NULL;\nCREATE DOMAIN NAME_DOMAIN varchar(100) NOT NULL;\nCREATE DOMAIN NAME_DOMAIN_NULL varchar(100) NULL;\n```\n\n#### Core Tables\n\n1. Person Management\n```sql\nCREATE TABLE tipo_identificacion (\n    tipo CODE_DOMAIN,\n    nombre NAME_DOMAIN,\n    CONSTRAINT tipo_identificacion_PK PRIMARY KEY (tipo),\n    CONSTRAINT tipo_identificacion_UQ UNIQUE (nombre)\n);\n\nCREATE TABLE persona (\n    tipo_identificacion CODE_DOMAIN,\n    identificacion CODE_DOMAIN,\n    primer_nombre NAME_DOMAIN,\n    segundo_nombre NAME_DOMAIN_NULL,\n    primer_apellido NAME_DOMAIN,\n    segundo_apellido NAME_DOMAIN_NULL,\n    direccion varchar(100) NULL,\n    telefono varchar(100) NULL,\n    fecha_nacimiento date NULL,\n    CONSTRAINT persona_PK PRIMARY KEY (identificacion),\n    CONSTRAINT persona_2_tipo_identificacion_FK \n        FOREIGN KEY(tipo_identificacion) \n        REFERENCES tipo_identificacion(tipo)\n);\n```\n\n2. Library Operations\n```sql\nCREATE TABLE libro (\n    isbn CODE_DOMAIN,\n    titulo NAME_DOMAIN,\n    editorial NAME_DOMAIN,\n    CONSTRAINT libro_PK PRIMARY KEY (isbn)\n);\n\nCREATE TABLE ejemplar (\n    isbn CODE_DOMAIN,\n    id ID_DOMAIN,\n    CONSTRAINT ejemplar_PK PRIMARY KEY (isbn, id),\n    CONSTRAINT ejemplar_2_libro_FK \n        FOREIGN KEY(isbn) \n        REFERENCES libro(isbn)\n);\n\nCREATE TABLE prestamo (\n    isbn CODE_DOMAIN,\n    id_ejemplar ID_DOMAIN,\n    codigo_estudiante CODE_DOMAIN,\n    fecha_prestamo timestamp NOT NULL DEFAULT now(),\n    dias_prestamo integer NOT NULL DEFAULT 3,\n    fecha_devolucion timestamp NULL,\n    CONSTRAINT prestamo_PK \n        PRIMARY KEY (isbn, id_ejemplar, codigo_estudiante, fecha_prestamo),\n    CONSTRAINT prestamo_2_ejemplar_FK \n        FOREIGN KEY(isbn, id_ejemplar) \n        REFERENCES ejemplar(isbn, id),\n    CONSTRAINT prestamo_2_estudiante_FK \n        FOREIGN KEY(codigo_estudiante) \n        REFERENCES estudiante(codigo)\n);\n```\n\n### Faculty Schema (facultad)\n\n#### Domain Definitions\n```sql\nCREATE DOMAIN CODE_DOMAIN varchar(20) NOT NULL;\nCREATE DOMAIN CODE_DOMAIN_NULL varchar(20) NULL;\nCREATE DOMAIN ID_DOMAIN integer NOT NULL;\nCREATE DOMAIN NAME_DOMAIN varchar(100) NOT NULL;\nCREATE DOMAIN NAME_DOMAIN_NULL varchar(100) NULL;\nCREATE DOMAIN SCORE_DOMAIN real NOT NULL DEFAULT 0;\n```\n\n#### Core Tables\n\n1. Academic Programs\n```sql\nCREATE TABLE tipo_programa (\n    tipo CODE_DOMAIN,\n    nombre NAME_DOMAIN,\n    CONSTRAINT tipo_programa_PK PRIMARY KEY (tipo),\n    CONSTRAINT tipo_programa_UQ UNIQUE (nombre)\n);\n\nCREATE TABLE carrera (\n    codigo CODE_DOMAIN,\n    nombre NAME_DOMAIN,\n    tipo CODE_DOMAIN,\n    CONSTRAINT carrera_PK PRIMARY KEY (codigo),\n    CONSTRAINT carrera_UQ UNIQUE (nombre),\n    CONSTRAINT carrera_2_tipo_programa_FK \n        FOREIGN KEY(tipo) \n        REFERENCES tipo_programa(tipo)\n);\n```\n\n2. Course Management\n```sql\nCREATE TABLE asignatura (\n    codigo CODE_DOMAIN,\n    nombre NAME_DOMAIN,\n    creditos integer NOT NULL DEFAULT 3,\n    CONSTRAINT asignatura_PK PRIMARY KEY (codigo),\n    CONSTRAINT asignatura_UQ UNIQUE (nombre)\n);\n\nCREATE TABLE grupo (\n    cod_carrera CODE_DOMAIN,\n    cod_asignatura CODE_DOMAIN,\n    periodo CODE_DOMAIN,\n    grupo ID_DOMAIN,\n    cupos integer NOT NULL DEFAULT 0,\n    cod_profesor CODE_DOMAIN_NULL,\n    CONSTRAINT grupo_PK \n        PRIMARY KEY (cod_carrera, cod_asignatura, periodo, grupo),\n    CONSTRAINT grupo_2_oferta_asignatura_FK \n        FOREIGN KEY(cod_carrera, cod_asignatura, periodo) \n        REFERENCES oferta_asignatura(cod_carrera, cod_asignatura, periodo)\n);\n```\n\n## Security Model\n\n### Role-Based Access Control\n\n1. Coordinator Role (role_coordinador)\n```sql\nGRANT USAGE ON SCHEMA facultad TO role_coordinador;\nGRANT SELECT, INSERT, UPDATE, DELETE ON facultad.persona TO role_coordinador;\nGRANT SELECT, INSERT, UPDATE, DELETE ON facultad.estudiante TO role_coordinador;\n```\n\n2. Professor Role (role_profesor)\n```sql\nGRANT USAGE ON SCHEMA facultad TO role_profesor;\nGRANT SELECT ON facultad.inscripcion TO role_profesor;\nGRANT UPDATE (nota1, nota2, nota3) ON facultad.inscripcion TO role_profesor;\n```\n\n3. Student Role (role_estudiante)\n```sql\nGRANT USAGE ON SCHEMA facultad TO role_estudiante;\nGRANT SELECT ON facultad.inscripcion TO role_estudiante;\nGRANT SELECT ON facultad.NotasPorEstudiante TO role_estudiante;\n```\n\n### Automated User Management\n\n```sql\nCREATE FUNCTION trg_AI_estudiante()\nRETURNS TRIGGER AS $$\nBEGIN\n    EXECUTE 'CREATE USER \"' || NEW.codigo || '\" WITH PASSWORD ''' || NEW.codigo || '''';\n    EXECUTE 'GRANT role_estudiante to \"' || NEW.codigo || '\";';\n    RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;\n```\n\n## Business Rules\n\n### Enrollment Controls\n\n```sql\nCREATE FUNCTION facultad.trg_control_inscripcion() \nRETURNS TRIGGER AS $$\nDECLARE\n    cupos_grupo INTEGER;\n    inscritos_grupo INTEGER;\nBEGIN\n    SELECT cupos INTO STRICT cupos_grupo\n    FROM facultad.grupo gru\n    WHERE gru.cod_carrera = new.cod_carrera \n    AND gru.cod_asignatura = new.cod_asignatura \n    AND gru.periodo = new.periodo \n    AND gru.grupo = new.grupo;\n    \n    -- Additional enrollment validation logic\nEND;\n$$ LANGUAGE plpgsql;\n```\n\n### Library Lending Rules\n\n```sql\nCREATE FUNCTION biblioteca.prestar_libro(\n    isbn varchar(20),\n    id_ejemplar INTEGER,\n    codigo_estudiante varchar(20),\n    dias_prestamo integer\n) RETURNS integer AS $$\nBEGIN\n    INSERT INTO biblioteca.prestamo(\n        isbn, id_ejemplar, codigo_estudiante, \n        fecha_prestamo, dias_prestamo\n    ) \n    VALUES(\n        isbn, id_ejemplar, codigo_estudiante, \n        now(), dias_prestamo\n    );\n    RETURN 0;\nEND;\n$$ LANGUAGE plpgsql;\n```\n\n## Integration Points\n\n### Cross-Database Views\n\n```sql\nCREATE VIEW facultad.DisponibilidadLibros AS\nSELECT *\nFROM dblink(\n    'dbname=biblioteca', \n    'select * from biblioteca.DisponibilidadLibros'\n)\nAS t1 (\n    isbn CODE_DOMAIN,\n    titulo NAME_DOMAIN,\n    editorial NAME_DOMAIN,\n    nombre NAME_DOMAIN,\n    id ID_DOMAIN\n);\n```\n\n## Operational Procedures\n\n### Regular Maintenance Tasks\n\nThe system requires regular maintenance procedures:\n1. Database optimization and cleanup\n2. User permission audits\n3. Performance monitoring\n4. Backup verification\n\n### Backup Strategy\n\nImplementation of a comprehensive backup strategy including:\n1. Daily full database backups\n2. Transaction log backups every hour\n3. Cross-database consistency checks\n4. Regular restore testing\n\n## Development Guidelines\n\n### Coding Standards\n\n1. Naming Conventions\n- Use snake_case for database objects\n- Prefix triggers with trg_\n- Prefix functions with their schema name\n\n2. Documentation Requirements\n- Inline comments for complex logic\n- Function header documentation\n- Change log maintenance\n\n### Version Control\n\nThe system uses semantic versioning:\n- Major version: Incompatible API changes\n- Minor version: Backwards-compatible functionality\n- Patch version: Backwards-compatible bug fixes\n\n## Maintenance and Support\n\n### Monitoring\n\nThe system requires monitoring of:\n1. Database link health\n2. Query performance\n3. Resource utilization\n4. Security events\n\n### Troubleshooting Procedures\n\nStandard procedures for:\n1. Database link failures\n2. Performance issues\n3. Security incidents\n4. Data consistency problems\n\nThis documentation provides a comprehensive overview of the University Distributed Database System.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalonov%2Fdb-university-postgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchalonov%2Fdb-university-postgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalonov%2Fdb-university-postgresql/lists"}