Coverage for cc_modules/cc_dirtytables.py: 100%

1"""

2 camcops_server/cc_modules/cc_dirtytables.py

3

4===============================================================================

5

6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

8

9 This file is part of CamCOPS.

10

11 CamCOPS is free software: you can redistribute it and/or modify

12 it under the terms of the GNU General Public License as published by

13 the Free Software Foundation, either version 3 of the License, or

14 (at your option) any later version.

15

16 CamCOPS is distributed in the hope that it will be useful,

17 but WITHOUT ANY WARRANTY; without even the implied warranty of

18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

19 GNU General Public License for more details.

20

21 You should have received a copy of the GNU General Public License

22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.

23

24===============================================================================

25

26**Representation of a "dirty table" -- one that a device is in the process of

27 uploading to/preserving.**

28

29"""

30

31 from typing import Optional

32

33 from sqlalchemy.orm import Mapped, mapped_column

34 from sqlalchemy.schema import ForeignKey

35

36 from camcops_server.cc_modules.cc_device import Device

37 from camcops_server.cc_modules.cc_sqla_coltypes import TableNameColType

38 from camcops_server.cc_modules.cc_sqlalchemy import Base

39

40

41# =============================================================================

42# DirtyTable

43# =============================================================================

44

45

46 class DirtyTable(Base):

47 """

48 Class to represent tables being modified during a client upload.

49 """

50

51 __tablename__ = "_dirty_tables"

52

53 id: Mapped[int] = mapped_column(

54 # new in 2.1.0; ditch composite PK

55 primary_key=True,

56 autoincrement=True,

57 )

58 device_id: Mapped[Optional[int]] = mapped_column(

59 ForeignKey(Device.id),

60 comment="Source tablet device ID",

61 )

62 tablename: Mapped[Optional[str]] = mapped_column(

63 TableNameColType,

64 comment="Table in the process of being preserved",

65 )