1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
mod mysql;
mod postgresql;
mod sqlite;
mod sqlserver;

use sql::{ForeignKeyWalker, IndexColumnWalker, IndexWalker, TableWalker};
use sql_schema_describer as sql;

pub(super) use mysql::MysqlIntrospectionFlavour;
pub(super) use postgresql::PostgresIntrospectionFlavour;
pub(super) use sqlite::SqliteIntrospectionFlavour;
pub(super) use sqlserver::SqlServerIntrospectionFlavour;

use schema_connector::Warnings;

use super::DatamodelCalculatorContext;

pub(crate) trait IntrospectionFlavour {
    /// For columns in PostgreSQL or SQLite views, if changed in PSL,
    /// we use the changed arity instead of the always optional value from the
    /// database.
    fn keep_previous_scalar_field_arity(&self, _: sql::ColumnWalker<'_>) -> bool {
        false
    }

    fn format_view_definition(&self, definition: &str) -> String {
        let opts = sqlformat::FormatOptions {
            uppercase: true,
            ..Default::default()
        };

        sqlformat::format(definition, &Default::default(), opts)
    }

    fn generate_warnings(&self, _ctx: &DatamodelCalculatorContext<'_>, _warnings: &mut Warnings) {}

    fn uses_row_level_ttl(&self, _ctx: &DatamodelCalculatorContext<'_>, _table: TableWalker<'_>) -> bool {
        false
    }

    fn uses_non_default_index_deferring(&self, _ctx: &DatamodelCalculatorContext<'_>, _index: IndexWalker<'_>) -> bool {
        false
    }

    fn uses_non_default_foreign_key_deferring(
        &self,
        _ctx: &DatamodelCalculatorContext<'_>,
        _foreign_key: ForeignKeyWalker<'_>,
    ) -> bool {
        false
    }

    fn uses_non_default_null_position(
        &self,
        _ctx: &DatamodelCalculatorContext<'_>,
        _column: IndexColumnWalker<'_>,
    ) -> bool {
        false
    }

    fn uses_exclude_constraint(&self, _ctx: &DatamodelCalculatorContext<'_>, _table: TableWalker<'_>) -> bool {
        false
    }
}